Fixed reading PNG iCCP compression method by radarhere · Pull Request #7823 · python-pillow/Pillow
Resolves #7817
| # according to PNG spec, the iCCP chunk contains: | |
| # Profile name 1-79 bytes (character string) | |
| # Null separator 1 byte (null character) | |
| # Compression method 1 byte (0) | |
| # Compressed profile n bytes (zlib with deflate compression) | |
| i = s.find(b"\0") | |
| logger.debug("iCCP profile name %r", s[:i]) | |
| logger.debug("Compression method %s", s[i]) | |
| comp_method = s[i] |
Pillow searches for b"\0", as the null separator at the end of the profile name.
Then it incorrectly uses the null separator as the compression method, when the compression method is the next byte.
The test image is a version of icc_profile_none.png, hex-edited to trigger the following error.
| if comp_method != 0: | |
| msg = f"Unknown compression method {comp_method} in iCCP chunk" | |
| raise SyntaxError(msg) |