Skip to content

IMAGING-398: Check the full size of the RGBE pixel buffer - #581

Open
ppkarwasz wants to merge 2 commits into
apache:masterfrom
ppkarwasz:fix/IMAGING-398-rgbe-allocation
Open

ppkarwasz wants to merge 2 commits into
apache:masterfrom
ppkarwasz:fix/IMAGING-398-rgbe-allocation

Conversation

@ppkarwasz

Copy link
Copy Markdown
Member

Fixes IMAGING-398.

RgbeInfo.getPixelData() allocated its pixel buffer as new float[3][Allocator.check(wd * ht)]. The check counted elements rather than bytes (the buffer is three float arrays, so up to 12 times the limit), and wd * ht was computed in int, so a large height could also overflow to a negative size and throw NegativeArraySizeException.

The size is now computed as a long and checked with Allocator.check(long, int) against 3 * Float.BYTES per pixel, so both cases throw AllocationRequestException before anything is allocated. This is the same pattern as the PCX, ImageBuilder and JPEG fixes (#552, #559, #570). Scan-line decoding is unchanged (see #576).

A generic memory allocation solution will be introduced in IMAGING-379.

A new parameterized test covers both cases with header-only files; without the change, the first one runs out of heap.

  • Read the contribution guidelines.
  • Read the ASF Generative Tooling Guidance.
  • I used AI to create any part of, or all of, this pull request: Claude Code (Claude Opus 5.5) helped analyze the decoder, draft the change and test, and write this description; I reviewed and verified everything.
  • Run a successful build using the default Maven goal with mvn.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request has a meaningful subject line and body.

RgbeInfo.getPixelData() checked width * height against the allocation
limit as an element count, computed in int, while it allocates three
float arrays of that length. A header declaring a large height passed
the check and requested up to 12 times the limit before reading any
scan line, and a product overflowing int reached the allocation as a
negative size.

Compute the pixel count as a long and check it against the size of the
three float arrays, so both cases throw AllocationRequestException.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant