pnggroup / libpng

LIBPNG: Portable Network Graphics support, official libpng repository
http://libpng.sf.net
Other
1.25k stars 611 forks source link

write palette check corrections #523

Closed jbowler closed 7 months ago

jbowler commented 7 months ago

The write palette check is off-by-one when checking the maximum palette index against the number of entries however, because of the implementation, the simple correction would fail if no palette check had been performed (for example for a non-palette image). This corrects both errors so that the code outputs a warning (but not an error) if a user of libpng writes an image with a PLTE which is one entry short.

The write palette check can be turned off on colour type 3 images (colour mapping images) but this is done by setting the 'maximum' palette index in the image to (-1). The ammended code works because it only executes for paletted images, it is dependent on palette checks being compiled in and they will always be checked unless the stored 'max' value is less than 0.