Skip to content

IMAGING-397: Fail on truncated uncompressed PSD image data - #580

Open
ppkarwasz wants to merge 2 commits into
apache:masterfrom
ppkarwasz:fix/IMAGING-397-psd-truncated-data
Open

ppkarwasz wants to merge 2 commits into
apache:masterfrom
ppkarwasz:fix/IMAGING-397-psd-truncated-data

Conversation

@ppkarwasz

Copy link
Copy Markdown
Member

Fixes IMAGING-397.

UncompressedDataReader reads channels × rows × columns samples through MyBitInputStream, which returns -1 at the end of the stream. The reader did not check for it, so a raw PSD whose image data is shorter than its header declares was decoded without error, with the missing samples set to 0xFF, and the read loop always ran for the full declared sample count.

The reader now throws an EOFException ("PSD: Missing Image Data") when the data ends early, matching what CompressedDataReader does for truncated RLE scanlines and what IMAGING-391 proposes for the TIFF bit reader. The check stays in the PSD reader: MyBitInputStream is shared with the LZW decoders, which rely on its end-of-stream sentinel.

A new test builds a 41-byte PSD declaring 3 × 1000 × 1000 samples with a single byte of image data; it fails without the change.

  • 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 reader, 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.

UncompressedDataReader read channels x rows x columns samples from the
image data section without checking for the end of the stream, filling
a truncated image with 0xFF samples. A file declaring more pixels than
it contains was decoded as if it were complete.

Throw an EOFException when the image data ends early, as
CompressedDataReader already does for missing scanlines.

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