fix: add decompression size limit to prevent decompression bomb DoS#1780
Open
eddieran wants to merge 1 commit intoHopding:masterfrom
Open
fix: add decompression size limit to prevent decompression bomb DoS#1780eddieran wants to merge 1 commit intoHopding:masterfrom
eddieran wants to merge 1 commit intoHopding:masterfrom
Conversation
Add a configurable maximum decompressed size limit (default 100 MB) to DecodeStream. When the accumulated decompressed output exceeds this threshold, an error is thrown instead of continuing to allocate memory. This prevents denial-of-service attacks where a small, crafted compressed PDF stream expands into gigabytes of data, exhausting the host's available memory. The limit is enforced in ensureBuffer() and defaults to 100 MB, which is sufficient for legitimate PDF content while blocking pathological expansion ratios. Fixes Hopding#1777
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
Adds a configurable maximum decompressed size limit to
DecodeStreamto prevent decompression bomb denial-of-service attacks.Problem: A crafted PDF can contain a small compressed stream that expands into gigabytes of data when decompressed, exhausting the host's available memory (decompression bomb / zip bomb). The
DecodeStreambase class had no upper bound on buffer growth —ensureBuffer()would keep doubling the internal buffer indefinitely.Fix: Enforce a maximum decompressed size (default 100 MB) in
ensureBuffer(). When the accumulated output exceeds this threshold, an error is thrown instead of continuing to allocate memory. The limit is configurable via themaxDecompressedSizeconstructor parameter for users who need to process legitimately large streams.Changes
DEFAULT_MAX_DECOMPRESSED_SIZEconstant (100 MB)maxDecompressedSizeparameter toDecodeStreamconstructor (with default)ensureBuffer()that throws before allocating beyond the limitBackward Compatibility
The new parameter has a default value, so all existing subclasses (
FlateStream,LZWStream,AsciiHexStream,Ascii85Stream,RunLengthStream) work without modification. The 100 MB default is large enough for any legitimate PDF content.Fixes #1777. Replaces #1779 (which was auto-closed when the source fork was deleted).