Skip to content

Add an optional cap on the size of a spilled stream - #729

Open
softvisionfd wants to merge 1 commit into
veraPDF:integrationfrom
softvision-dev:bound-spilled-stream-size
Open

Add an optional cap on the size of a spilled stream#729
softvisionfd wants to merge 1 commit into
veraPDF:integrationfrom
softvision-dev:bound-spilled-stream-size

Conversation

@softvisionfd

Copy link
Copy Markdown

Summary

getSeekableStream(InputStream, Integer maxStreamSize) already supports a size limit for a stream that is
spilled to a temporary file, but the no-limit overload getSeekableStream(InputStream) always passes
null, so no caller ever sets one. A small input whose decoded content expands without bound (a
"decompression bomb") can therefore be written to a temporary file in full.

This adds an opt-in cap and wires it into the no-limit overload, which is the path taken by decoded object
streams and other non-seekable input.

Changes

  • SeekableInputStream.setMaxStreamSize(int) / getMaxStreamSize() set an optional hard cap, in bytes, on
    a single spilled stream.
  • getSeekableStream(InputStream) now passes that cap to the existing size-limited overload. A stream
    exceeding the cap is rejected with a VeraPDFParserException instead of being written out.

Backward compatibility

The cap defaults to null (no cap), so behaviour is unchanged unless a caller sets one. The change is
independent of #728 and can be merged in any order. Java 8 compatible, and all existing parser tests pass.

getSeekableStream(InputStream, Integer maxStreamSize) already supported a size
limit, but the no-limit overload getSeekableStream(InputStream) passed null, so
no caller ever set one. A small input whose decoded content expands without
bound (a decompression bomb) could therefore be written to a temporary file in
full.

Add an optional static cap SeekableInputStream.setMaxStreamSize and pass it
from the no-limit overload, which is the path taken by decoded object streams
and other non-seekable input. A stream exceeding the cap is rejected with a
VeraPDFParserException instead of being written out.

Default is null (no cap), so behaviour is unchanged unless a cap is set.
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 50 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: b6988a5e-b5cc-4d1f-8558-177c8b3827f9

📥 Commits

Reviewing files that changed from the base of the PR and between 815f8cc and e75d8e2.

📒 Files selected for processing (1)
  • src/main/java/org/verapdf/io/SeekableInputStream.java

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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