ppkarwasz opened a new pull request, #585: URL: https://github.com/apache/commons-imaging/pull/585
Fixes [IMAGING-403](https://issues.apache.org/jira/browse/IMAGING-403). Two decoders multiplied the image dimensions in `int` before the allocation check: - `GifImageParser.readImageDescriptor` computed `imageWidth * imageHeight` and passed it to the LZW decompressor. For a 65535 × 65535 frame the size was -131071 and `new ByteArrayOutputStream(-131071)` threw `IllegalArgumentException`. - `XpmImageParser.readXpmImage` called `Allocator.check(Integer.SIZE, width * height)` (and `Byte.SIZE` / `Short.SIZE` for 8- and 16-bit images): arguments swapped, element size in bits, product in `int`. For 65535 × 65535 the check passed and creating the raster threw `IllegalArgumentException` or `NegativeArraySizeException`. Both now compute the pixel count as a `long` and call `Allocator.check(long, int)` with the element size in bytes, so these inputs throw `AllocationRequestException`, as other decoders do. For 8- and 16-bit XPM images the check was previously 8 times stricter than intended (bits instead of bytes); it now matches the other formats. The XPM part is the same change as in #401 (Marcono1234), which also covers many other call sites and has not been merged; this PR only fixes these two decoders. Tests: `GifReadTest.testFrameSizeExceedsAllocationLimit` (28-byte GIF) and `XpmParserTest.testImageSizeExceedsAllocationLimit` (8-, 16- and 32-bit XPM headers); all fail without the change. - [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 decoders, 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]
