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.
|
@ -119,6 +119,13 @@ void png_reader::init()
|
|||
throw image_reader_exception("failed to create info_ptr");
|
||||
}
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr,0,0);
|
||||
fclose(fp);
|
||||
throw image_reader_exception("failed to read");
|
||||
}
|
||||
|
||||
png_set_read_fn(png_ptr, (png_voidp)fp, png_read_data);
|
||||
|
||||
png_set_sig_bytes(png_ptr,8);
|
||||
|
@ -168,6 +175,13 @@ void png_reader::read(unsigned x0, unsigned y0,image_data_32& image)
|
|||
throw image_reader_exception("failed to create info_ptr");
|
||||
}
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr,0,0);
|
||||
fclose(fp);
|
||||
throw image_reader_exception("failed to read");
|
||||
}
|
||||
|
||||
png_set_read_fn(png_ptr, (png_voidp)fp, png_read_data);
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
|
|
9
tests/data/pngsuite/PngSuite.LICENSE
Normal file
|
@ -0,0 +1,9 @@
|
|||
PngSuite
|
||||
--------
|
||||
|
||||
Permission to use, copy, modify and distribute these images for any
|
||||
purpose and without fee is hereby granted.
|
||||
|
||||
|
||||
(c) Willem van Schaik, 1996, 2011
|
||||
|
25
tests/data/pngsuite/PngSuite.README
Normal file
|
@ -0,0 +1,25 @@
|
|||
PNGSUITE
|
||||
----------------
|
||||
|
||||
testset for PNG-(de)coders
|
||||
created by Willem van Schaik
|
||||
------------------------------------
|
||||
|
||||
This is a collection of graphics images created to test the png applications
|
||||
like viewers, converters and editors. All (as far as that is possible)
|
||||
formats supported by the PNG standard are represented.
|
||||
|
||||
The suite consists of the following files:
|
||||
|
||||
- PngSuite.README - this file
|
||||
- PngSuite.LICENSE - the PngSuite is freeware
|
||||
- PngSuite.png - image with PngSuite logo
|
||||
- PngSuite.tgz - archive of all PNG testfiles
|
||||
- PngSuite.zip - same in .zip format for PCs
|
||||
|
||||
|
||||
--------
|
||||
(c) Willem van Schaik
|
||||
willem@schaik.com
|
||||
Calgary, April 2011
|
||||
|
BIN
tests/data/pngsuite/PngSuite.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
tests/data/pngsuite/basi0g01.png
Normal file
After Width: | Height: | Size: 217 B |
BIN
tests/data/pngsuite/basi0g02.png
Normal file
After Width: | Height: | Size: 154 B |
BIN
tests/data/pngsuite/basi0g04.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
tests/data/pngsuite/basi0g08.png
Normal file
After Width: | Height: | Size: 254 B |
BIN
tests/data/pngsuite/basi0g16.png
Normal file
After Width: | Height: | Size: 299 B |
BIN
tests/data/pngsuite/basi2c08.png
Normal file
After Width: | Height: | Size: 315 B |
BIN
tests/data/pngsuite/basi2c16.png
Normal file
After Width: | Height: | Size: 595 B |
BIN
tests/data/pngsuite/basi3p01.png
Normal file
After Width: | Height: | Size: 132 B |
BIN
tests/data/pngsuite/basi3p02.png
Normal file
After Width: | Height: | Size: 193 B |
BIN
tests/data/pngsuite/basi3p04.png
Normal file
After Width: | Height: | Size: 327 B |
BIN
tests/data/pngsuite/basi3p08.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
tests/data/pngsuite/basi4a08.png
Normal file
After Width: | Height: | Size: 214 B |
BIN
tests/data/pngsuite/basi4a16.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
tests/data/pngsuite/basi6a08.png
Normal file
After Width: | Height: | Size: 361 B |
BIN
tests/data/pngsuite/basi6a16.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
tests/data/pngsuite/basn0g01.png
Normal file
After Width: | Height: | Size: 164 B |
BIN
tests/data/pngsuite/basn0g02.png
Normal file
After Width: | Height: | Size: 104 B |
BIN
tests/data/pngsuite/basn0g04.png
Normal file
After Width: | Height: | Size: 145 B |
BIN
tests/data/pngsuite/basn0g08.png
Normal file
After Width: | Height: | Size: 138 B |
BIN
tests/data/pngsuite/basn0g16.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
tests/data/pngsuite/basn2c08.png
Normal file
After Width: | Height: | Size: 145 B |
BIN
tests/data/pngsuite/basn2c16.png
Normal file
After Width: | Height: | Size: 302 B |
BIN
tests/data/pngsuite/basn3p01.png
Normal file
After Width: | Height: | Size: 112 B |
BIN
tests/data/pngsuite/basn3p02.png
Normal file
After Width: | Height: | Size: 146 B |
BIN
tests/data/pngsuite/basn3p04.png
Normal file
After Width: | Height: | Size: 216 B |
BIN
tests/data/pngsuite/basn3p08.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
tests/data/pngsuite/basn4a08.png
Normal file
After Width: | Height: | Size: 126 B |
BIN
tests/data/pngsuite/basn4a16.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
tests/data/pngsuite/basn6a08.png
Normal file
After Width: | Height: | Size: 184 B |
BIN
tests/data/pngsuite/basn6a16.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
tests/data/pngsuite/bgai4a08.png
Normal file
After Width: | Height: | Size: 214 B |
BIN
tests/data/pngsuite/bgai4a16.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
tests/data/pngsuite/bgan6a08.png
Normal file
After Width: | Height: | Size: 184 B |
BIN
tests/data/pngsuite/bgan6a16.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
tests/data/pngsuite/bgbn4a08.png
Normal file
After Width: | Height: | Size: 140 B |
BIN
tests/data/pngsuite/bggn4a16.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
tests/data/pngsuite/bgwn6a08.png
Normal file
After Width: | Height: | Size: 202 B |
BIN
tests/data/pngsuite/bgyn6a16.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
tests/data/pngsuite/ccwn2c08.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
tests/data/pngsuite/ccwn3p08.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
tests/data/pngsuite/cdfn2c08.png
Normal file
After Width: | Height: | Size: 404 B |
BIN
tests/data/pngsuite/cdhn2c08.png
Normal file
After Width: | Height: | Size: 344 B |
BIN
tests/data/pngsuite/cdsn2c08.png
Normal file
After Width: | Height: | Size: 232 B |
BIN
tests/data/pngsuite/cdun2c08.png
Normal file
After Width: | Height: | Size: 724 B |
BIN
tests/data/pngsuite/ch1n3p04.png
Normal file
After Width: | Height: | Size: 258 B |
BIN
tests/data/pngsuite/ch2n3p08.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
tests/data/pngsuite/cm0n0g04.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
tests/data/pngsuite/cm7n0g04.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
tests/data/pngsuite/cm9n0g04.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
tests/data/pngsuite/cs3n2c16.png
Normal file
After Width: | Height: | Size: 214 B |
BIN
tests/data/pngsuite/cs3n3p08.png
Normal file
After Width: | Height: | Size: 259 B |
BIN
tests/data/pngsuite/cs5n2c08.png
Normal file
After Width: | Height: | Size: 186 B |
BIN
tests/data/pngsuite/cs5n3p08.png
Normal file
After Width: | Height: | Size: 271 B |
BIN
tests/data/pngsuite/cs8n2c08.png
Normal file
After Width: | Height: | Size: 149 B |
BIN
tests/data/pngsuite/cs8n3p08.png
Normal file
After Width: | Height: | Size: 256 B |
BIN
tests/data/pngsuite/ct0n0g04.png
Normal file
After Width: | Height: | Size: 273 B |
BIN
tests/data/pngsuite/ct1n0g04.png
Normal file
After Width: | Height: | Size: 792 B |
BIN
tests/data/pngsuite/cten0g04.png
Normal file
After Width: | Height: | Size: 748 B |
BIN
tests/data/pngsuite/ctfn0g04.png
Normal file
After Width: | Height: | Size: 722 B |
BIN
tests/data/pngsuite/ctgn0g04.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
tests/data/pngsuite/cthn0g04.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
tests/data/pngsuite/ctjn0g04.png
Normal file
After Width: | Height: | Size: 947 B |
BIN
tests/data/pngsuite/ctzn0g04.png
Normal file
After Width: | Height: | Size: 753 B |
BIN
tests/data/pngsuite/f00n0g08.png
Normal file
After Width: | Height: | Size: 319 B |
BIN
tests/data/pngsuite/f00n2c08.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
tests/data/pngsuite/f01n0g08.png
Normal file
After Width: | Height: | Size: 321 B |
BIN
tests/data/pngsuite/f01n2c08.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
tests/data/pngsuite/f02n0g08.png
Normal file
After Width: | Height: | Size: 355 B |
BIN
tests/data/pngsuite/f02n2c08.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
tests/data/pngsuite/f03n0g08.png
Normal file
After Width: | Height: | Size: 389 B |
BIN
tests/data/pngsuite/f03n2c08.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
tests/data/pngsuite/f04n0g08.png
Normal file
After Width: | Height: | Size: 269 B |
BIN
tests/data/pngsuite/f04n2c08.png
Normal file
After Width: | Height: | Size: 985 B |
BIN
tests/data/pngsuite/f99n0g04.png
Normal file
After Width: | Height: | Size: 426 B |
BIN
tests/data/pngsuite/g03n0g16.png
Normal file
After Width: | Height: | Size: 345 B |
BIN
tests/data/pngsuite/g03n2c08.png
Normal file
After Width: | Height: | Size: 370 B |
BIN
tests/data/pngsuite/g03n3p04.png
Normal file
After Width: | Height: | Size: 214 B |
BIN
tests/data/pngsuite/g04n0g16.png
Normal file
After Width: | Height: | Size: 363 B |
BIN
tests/data/pngsuite/g04n2c08.png
Normal file
After Width: | Height: | Size: 377 B |
BIN
tests/data/pngsuite/g04n3p04.png
Normal file
After Width: | Height: | Size: 219 B |
BIN
tests/data/pngsuite/g05n0g16.png
Normal file
After Width: | Height: | Size: 339 B |
BIN
tests/data/pngsuite/g05n2c08.png
Normal file
After Width: | Height: | Size: 350 B |
BIN
tests/data/pngsuite/g05n3p04.png
Normal file
After Width: | Height: | Size: 206 B |
BIN
tests/data/pngsuite/g07n0g16.png
Normal file
After Width: | Height: | Size: 321 B |
BIN
tests/data/pngsuite/g07n2c08.png
Normal file
After Width: | Height: | Size: 340 B |
BIN
tests/data/pngsuite/g07n3p04.png
Normal file
After Width: | Height: | Size: 207 B |
BIN
tests/data/pngsuite/g10n0g16.png
Normal file
After Width: | Height: | Size: 262 B |
BIN
tests/data/pngsuite/g10n2c08.png
Normal file
After Width: | Height: | Size: 285 B |
BIN
tests/data/pngsuite/g10n3p04.png
Normal file
After Width: | Height: | Size: 214 B |
BIN
tests/data/pngsuite/g25n0g16.png
Normal file
After Width: | Height: | Size: 383 B |
BIN
tests/data/pngsuite/g25n2c08.png
Normal file
After Width: | Height: | Size: 405 B |
BIN
tests/data/pngsuite/g25n3p04.png
Normal file
After Width: | Height: | Size: 215 B |
BIN
tests/data/pngsuite/oi1n0g16.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
tests/data/pngsuite/oi1n2c16.png
Normal file
After Width: | Height: | Size: 302 B |
BIN
tests/data/pngsuite/oi2n0g16.png
Normal file
After Width: | Height: | Size: 179 B |
BIN
tests/data/pngsuite/oi2n2c16.png
Normal file
After Width: | Height: | Size: 314 B |