Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
image/png: decoding of trailing IDAT chunks #14936
Decoding of some PNG files generated by GDAL2Tiles (raster map tile generator) fails with the error message "not enough pixel data". Most other decoders can read these files without any issues.
Even though the error message suggests otherwise, the problematic files actually contain too much data. Following the expected IDAT chunks containing all of the image data, there is an additional zero-length IDAT chunk.
According to the PNG specification, zero-length IDAT chunks are valid. Trailing garbage may not be valid, but the spec explicitly allows ignoring of errors that have no effect on the processing of the image.
The error message "not enough pixel data" is generated after the decoder successfully decodes the image: it then encounters the trailing zero-length IDAT chunk and attempts to decode it as if it were the first IDAT chunk in the image.
No error is generated when the decoder encounters trailing IDAT chunks that contain actual image data, as long as that image data can be decoded with the PNG header (and palette) already seen. This allows users to craft images that trick the decoder into decoding a second image appended after the first.
CL with proposed fix following.