Skip to content

[IMAGING-388] Prevent PNG scanline size overflow - #566

Open
dajiaohuang wants to merge 1 commit into
apache:masterfrom
dajiaohuang:IMAGING-388-png-scanline-overflow
Open

dajiaohuang wants to merge 1 commit into
apache:masterfrom
dajiaohuang:IMAGING-388-png-scanline-overflow

Conversation

@dajiaohuang

Copy link
Copy Markdown

Fixes IMAGING-388.

What

PNG scanline sizing used 32-bit multiplication for bitsPerPixel * width and rounded the result to bytes with another int expression. For the reported 536,870,921-pixel, 8-bit grayscale row, the product wraps to 72 bits and produces a 9-byte row buffer. Decoding then indexes beyond that buffer.

Compute scanline size in long, reject results that cannot be represented as a Java array length with ImagingException, and use long arithmetic for per-sample offsets. BitParser now reports an out-of-row sample as ImagingException rather than leaking ArrayIndexOutOfBoundsException.

Tests

  • Regression verifies 536,870,921 grayscale pixels require a 536,870,921-byte row without allocating that buffer.
  • Regression verifies unrepresentable scanline lengths and out-of-row/overflowing sample offsets fail with ImagingException.
  • Default Maven build (mvn): BUILD SUCCESS; 1,265 tests, 0 failures, 0 errors, 7 skipped. The task-local checkout was normalized to the repository's LF source convention for Checkstyle.

Contribution checklist

  • Read the contribution guidelines.
  • Read the ASF Generative Tooling Guidance.
  • AI use: OpenAI Codex (gpt-6-luna) assisted with source analysis, implementation, and regression tests. Human operator: dajiaohuang.
  • Ran the default Maven build successfully.
  • Added behavioral regression tests.
  • This description explains the issue and change.
  • Commit subject and body identify the issue and summarize the change.

Calculate scanline byte lengths and sample offsets without int overflow. Reject unrepresentable or out-of-row lengths with ImagingException and add regression coverage.
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