Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed reading PNG iCCP compression method #7823

Merged
merged 2 commits into from Mar 11, 2024

Conversation

radarhere
Copy link
Member

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)

@hugovk hugovk merged commit 1b6e68e into python-pillow:main Mar 11, 2024
57 checks passed
@hugovk hugovk added the Bug Any unexpected behavior, until confirmed feature. label Mar 11, 2024
@radarhere radarhere deleted the png_iccp branch March 12, 2024 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PNG iCCP chunk profile compression type verification seems wrong
2 participants