Add an optional cap on the size of a spilled stream - #729
Open
softvisionfd wants to merge 1 commit into
Open
Conversation
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.
|
Warning Review limit reachedNext included review available in 50 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
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. Comment |
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.
Summary
getSeekableStream(InputStream, Integer maxStreamSize)already supports a size limit for a stream that isspilled to a temporary file, but the no-limit overload
getSeekableStream(InputStream)always passesnull, 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, ona single spilled stream.
getSeekableStream(InputStream)now passes that cap to the existing size-limited overload. A streamexceeding the cap is rejected with a
VeraPDFParserExceptioninstead of being written out.Backward compatibility
The cap defaults to
null(no cap), so behaviour is unchanged unless a caller sets one. The change isindependent of #728 and can be merged in any order. Java 8 compatible, and all existing parser tests pass.