Fix decompression bomb vulnerability in DecodeStream#1779
Closed
eddieran wants to merge 1 commit intoHopding:masterfrom
Closed
Fix decompression bomb vulnerability in DecodeStream#1779eddieran wants to merge 1 commit intoHopding:masterfrom
eddieran wants to merge 1 commit intoHopding:masterfrom
Conversation
DecodeStream.ensureBuffer() doubles its buffer without any upper bound, allowing crafted compressed streams to allocate gigabytes of memory and crash the process. Add a configurable maximum buffer size (default 256 MB) that throws a clear error when exceeded. Fixes #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 maximum buffer size limit to
DecodeStream.ensureBuffer()to prevent decompression bomb attacks.ensureBuffer()previously doubled its buffer without any upper bound, allowing a crafted Flate/LZW stream to allocate gigabytes of memory and crash the process duringPDFDocument.load()maxBufferSizeproperty (default 256 MB) that throws a descriptive error when exceededDecodeStream.maxBufferSizefor legitimate large documentsFixes #1777
Changes
src/core/streams/DecodeStream.ts:DEFAULT_MAX_BUFFER_SIZEconstant (256 MB)maxBufferSizeproperty toDecodeStreamclassensureBuffer()before buffer allocationTest plan
DecodeStream.maxBufferSizecan be increased for legitimate large documents