Repository navigation
Conversation
PngChunkIccp inflated the embedded ICC profile until the compressed data ended, so a small iCCP chunk could expand to hundreds of megabytes, although an ICC profile declares its own size in the first 4 bytes of its header and ICC_Profile ignores any data past it. Inflate the 132-byte ICC header first, check the declared size against the Allocator limit, then read exactly that many bytes incrementally with IOUtils.toByteArray(InputStream, int, int). A profile shorter than declared, or declaring less than a header, throws ImagingException. Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes IMAGING-399.
PngChunkIccpinflated the embedded ICC profile withIOUtils.toByteArray(new InflaterInputStream(...)), reading until the compressed data ended. An ICC profile declares its own size in the first 4 bytes of its header, andICC_Profile.getInstancerequires at least that many bytes and ignores anything after them, so nothing past the declared size is useful.The chunk now:
Allocator.checkByteArray;IOUtils.toByteArray(InputStream, int, int)(Commons IO 2.21.0+), which reads in chunks, so memory follows the data actually inflated and inflation stops at the declared size.A profile that ends before its declared size throws
ImagingException, asPngReadTest.testUncaughtExceptionOssFuzz33691expects for malformed input.Behavior changes:
getUncompressedProfile()/getIccProfileBytes()return the profile trimmed to its declared size, without trailing data.getBufferedImagefor a PNG that also has an sRGB chunk (the PNG specification does not allow both).Tests:
PngChunkIccpTestnow uses profile data with a valid declared size and covers longer, shorter, oversized and undersized declarations, plus a round trip of the JDK's sRGB profile throughICC_Profile.getInstance. All 53 ICC profiles installed on my machine declare exactly their file length.mvn.