Palette index checking fixes
The palette index checking function is called by default but only if some *other* transformation is happening. This makes the 'get palette max' public API disfunctional (sometimes it works, sometimes it returns 0) and causes the supposed default behaviour of checking the palette index only to work sometimes. It works in pngtest, it doesn't work in pngcp. The check in pngread also has an off-by-one error; the number recorded is the highest index found so it should be checked to ensure that it is less than the palette length but it was checked for being greater. The pull request includes a set of 8 files which all have the full range of possible indices including one (the highest) which is invalid because the PLTE chunk is one short of the maximum for each bit depth. Signed-off-by: John Bowler <jbowler@acm.org>
BIN
contrib/testpngs/badpal/small-palette-1.png
Normal file
|
After Width: | Height: | Size: 271 B |
BIN
contrib/testpngs/badpal/small-palette-2.png
Normal file
|
After Width: | Height: | Size: 277 B |
BIN
contrib/testpngs/badpal/small-palette-4.png
Normal file
|
After Width: | Height: | Size: 315 B |
BIN
contrib/testpngs/badpal/small-palette-8.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
contrib/testpngs/badpal/test-palette-1.png
Normal file
|
After Width: | Height: | Size: 432 B |
BIN
contrib/testpngs/badpal/test-palette-2.png
Normal file
|
After Width: | Height: | Size: 499 B |
BIN
contrib/testpngs/badpal/test-palette-4.png
Normal file
|
After Width: | Height: | Size: 591 B |
BIN
contrib/testpngs/badpal/test-palette-8.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
@ -568,7 +568,7 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
|
||||
if (png_ptr->transformations)
|
||||
if (png_ptr->transformations || png_ptr->num_palette_max >= 0)
|
||||
png_do_read_transformations(png_ptr, &row_info);
|
||||
#endif
|
||||
|
||||
@ -785,7 +785,7 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
|
||||
/* Report invalid palette index; added at libng-1.5.10 */
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
|
||||
png_ptr->num_palette_max > png_ptr->num_palette)
|
||||
png_ptr->num_palette_max >= png_ptr->num_palette)
|
||||
png_benign_error(png_ptr, "Read palette index exceeding num_palette");
|
||||
#endif
|
||||
|
||||
|
||||