Repository navigation
IMAGING-379: Fix int overflow that bypasses the JPEG raster allocation guard - #570
Open
sharanggupta wants to merge 2 commits into
Open
sharanggupta wants to merge 2 commits into
sharanggupta wants to merge 2 commits into
Conversation
JpegDecoder guarded the output raster with Allocator.check(Integer.BYTES * width * height), but that product is computed in int and overflows for large SOF dimensions (0x8000 x 0x8000 wraps to 0), so the guard passes and Raster.createPackedRaster then allocates from the raw dimensions. Compute the request in long and use the overflow-safe two-argument Allocator.check overload. Assisted-By: Claude (Anthropic)
Assisted-By: Claude (Anthropic)
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.
JpegDecoderguards the output raster withAllocator.check(Integer.BYTES * width * height), but that product is computed inintand overflows for large SOF dimensions (e.g. 0x8000 x 0x8000 wraps to 0), so the guard passes andRaster.createPackedRasterthen allocates from the raw dimensions: an uncontrolled multi-gigabyte allocation from a tiny crafted JPEG. This computes the request inlongand uses the existing overflow-safe two-argumentAllocator.checkoverload. Adds aJpegDecoderTestcase that fails without the change.Reported privately to the ASF security team, who confirmed the analysis and pointed to IMAGING-379 as the right home for this hardening (resource exhaustion is out of scope as a security report), suggesting this public contribution.