Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PNG: Ignore invalid gamma chunks #2021

Merged
merged 3 commits into from
Feb 21, 2022
Merged

PNG: Ignore invalid gamma chunks #2021

merged 3 commits into from
Feb 21, 2022

Conversation

brianpopow
Copy link
Collaborator

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This PR handles another edge case when the gamma chunk does not contain enough data.

@JimBobSquarePants
Copy link
Member

What does libpng do in this situation? Gamma chunk is not mandatory and can use default values in certain situations.

http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html

@brianpopow
Copy link
Collaborator Author

What does libpng do in this situation? Gamma chunk is not mandatory and can use default values in certain situations.

http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html

I think you are right, its not mandatory.

libpng only shows a warning, but decodes the image.

libpng output:

Click to expand! Testing libpng version 1.6.38.git with zlib version 1.2.11

libpng version 1.6.38.git
Copyright (c) 2018-2020 Cosmin Truta
Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
Copyright (c) 1996-1997 Andreas Dilger
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
library (10638): libpng version 1.6.38.git
pngtest (10638): libpng version 1.6.38.git

Testing length_gama.png:
length_gama.png: libpng warning: gAMA: invalid

length_gama.png: 1 libpng warnings found
Files length_gama.png and pngout.png are different
Was length_gama.png written with the same maximum IDAT chunk size (8192 bytes),
filtering heuristic (libpng default), compression level (zlib default),
and zlib version (1.2.11)?

length_gama.png: libpng warning: gAMA: invalid

Pass 0: rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
rwrw
length_gama.png: 2 libpng warnings found
Files length_gama.png and pngout.png are different

length_gama.png: libpng warning: gAMA: invalid

length_gama.png: 3 libpng warnings found
Files length_gama.png and pngout.png are different

PASS (4 zero samples)
libpng passes test
Default limits:
width_max = 1000000
height_max = 1000000
cache_max = 1000
malloc_max = 8000000

@brianpopow brianpopow changed the title Throw exception, if gamma chunk does not contain enough data PNG: Ignore invalid gamma chunks Feb 21, 2022
@brianpopow brianpopow added this to the 2.*.* milestone Feb 21, 2022
Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@brianpopow brianpopow merged commit c059656 into main Feb 21, 2022
@brianpopow brianpopow deleted the bp/invalidgamma branch February 21, 2022 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants