throw instead of abort on invalid PNG images #1213

Closed
springmeyer opened this Issue May 14, 2012 · 0 comments

Projects

None yet

2 participants

@springmeyer
Mapnik member

Some of the corrupt images from http://www.schaik.com/pngsuite/ trigger aborts. We should avoid this.

~/Downloads/PngSuite-2011apr25$ for i in $(ls *png); do python -c "import mapnik;mapnik.Image.open('$i')";done
libpng warning: Invalid color type in IHDR
libpng error: Invalid IHDR data
Abort trap: 6
libpng warning: Invalid color type in IHDR
libpng error: Invalid IHDR data
Abort trap: 6
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError: xcrn0g04.png is not a png file
libpng error: IDAT: CRC error
Abort trap: 6
libpng warning: Invalid bit depth in IHDR
libpng warning: Invalid color type/bit depth combination in IHDR
libpng error: Invalid IHDR data
Abort trap: 6
libpng warning: Invalid bit depth in IHDR
libpng warning: Invalid color type/bit depth combination in IHDR
libpng error: Invalid IHDR data
Abort trap: 6
libpng warning: Invalid bit depth in IHDR
libpng error: Invalid IHDR data
Abort trap: 6
libpng error: No image in file
Abort trap: 6
libpng error: IHDR: CRC error
Abort trap: 6
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError: xlfn0g04.png is not a png file
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError: xs1n0g01.png is not a png file
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError: xs2n0g01.png is not a png file
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError: xs4n0g01.png is not a png file
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError: xs7n0g01.png is not a png file
@artemp artemp pushed a commit that closed this issue Jun 7, 2012
Carl Simonson Catch and throw PNG exceptions - fixes #1213
The png library uses setjmp/longjmp to throw exceptions when reading. If this
is not set up, the png library calls abort(). This change handles the errors
and throws a C++ exception instead.

This issue was found by testing images from pngsuite at
http://www.schaik.com/pngsuite/. These images are included and a unit test was
added to test both images that should be successful and images that should
throw an exception.
cd7ad3e
@artemp artemp closed this in cd7ad3e Jun 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment