ppkarwasz opened a new pull request, #582: URL: https://github.com/apache/commons-imaging/pull/582
Fixes [IMAGING-399](https://issues.apache.org/jira/browse/IMAGING-399). `PngChunkIccp` inflated the embedded ICC profile with `IOUtils.toByteArray(new InflaterInputStream(...))`, reading until the compressed data ended. An ICC profile declares its own size in the first 4 bytes of its header, and `ICC_Profile.getInstance` requires at least that many bytes and ignores anything after them, so nothing past the declared size is useful. The chunk now: 1. inflates the 132-byte ICC header (header plus tag count, the smallest valid profile) and reads the declared size; 2. rejects sizes below 132 and checks the size with `Allocator.checkByteArray`; 3. reads exactly the declared size with `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`, as `PngReadTest.testUncaughtExceptionOssFuzz33691` expects for malformed input. Behavior changes: - `getUncompressedProfile()` / `getIccProfileBytes()` return the profile trimmed to its declared size, without trailing data. - A malformed iCCP chunk now fails when the chunk is read, including in `getBufferedImage` for a PNG that also has an sRGB chunk (the PNG specification does not allow both). Tests: `PngChunkIccpTest` now 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 through `ICC_Profile.getInstance`. All 53 ICC profiles installed on my machine declare exactly their file length. - [x] Read the contribution guidelines. - [x] Read the ASF Generative Tooling Guidance. - [x] I used AI to create any part of, or all of, this pull request: Claude Code (Claude Opus 5.5) helped analyze the chunk parser and the JDK's ICC_Profile validation, draft the change and tests, and write this description; I reviewed and verified everything. - [x] Run a successful build using the default Maven goal with `mvn`. - [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [x] Each commit in the pull request has a meaningful subject line and body. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
