Repository navigation
Conversation
GifImageParser computed the frame size as imageWidth * imageHeight in int and XpmImageParser checked the raster size with Allocator.check(Integer.SIZE, width * height): arguments swapped, a bit count as element size and an int product. Dimensions of 65535 x 65535 overflowed to a negative size that the check accepted, so decoding failed with IllegalArgumentException or NegativeArraySizeException. Compute the pixel count as a long and check it with Allocator.check(long, int) and the element size in bytes, so both cases throw AllocationRequestException. 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-403.
Two decoders multiplied the image dimensions in
intbefore the allocation check:GifImageParser.readImageDescriptorcomputedimageWidth * imageHeightand passed it to the LZW decompressor. For a 65535 × 65535 frame the size was -131071 andnew ByteArrayOutputStream(-131071)threwIllegalArgumentException.XpmImageParser.readXpmImagecalledAllocator.check(Integer.SIZE, width * height)(andByte.SIZE/Short.SIZEfor 8- and 16-bit images): arguments swapped, element size in bits, product inint. For 65535 × 65535 the check passed and creating the raster threwIllegalArgumentExceptionorNegativeArraySizeException.Both now compute the pixel count as a
longand callAllocator.check(long, int)with the element size in bytes, so these inputs throwAllocationRequestException, 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) andXpmParserTest.testImageSizeExceedsAllocationLimit(8-, 16- and 32-bit XPM headers); all fail without the change.mvn.