Fix integer overflow in XRef stream byte width parsing#1781
Open
eddieran wants to merge 1 commit intoHopding:masterfrom
Open
Fix integer overflow in XRef stream byte width parsing#1781eddieran wants to merge 1 commit intoHopding:masterfrom
eddieran wants to merge 1 commit intoHopding:masterfrom
Conversation
The /W array values from XRef streams were read without validation. A crafted PDF with large byte widths (e.g. /W [100, 100, 100]) causes excessive byte reads, integer overflow via bit shifting in parseEntries(), and NaN propagation. This adds: - Validation that each /W byte width is 0-8 per ISO 32000-1:2008, Table 17 - Bounds checking in parseEntries() for premature end of stream Fixes Hopding#1776
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
Fixes #1776 -- integer overflow in XRef stream byte width parsing.
The
/Warray values from XRef streams are read without validation. These widths control loop bounds inparseEntries(). A crafted PDF with/W [100, 100, 100]causes excessive byte reads, integer overflow via bit shifting, and NaN propagation.Changes
/Wbyte widths after reading from the array. Each width must be 0--8 per the PDF spec (ISO 32000-1:2008, Table 17). ThrowsInvalidXRefStreamByteWidthErrorfor out-of-range values.bytes.next()inparseEntries()to gracefully handle premature end-of-stream instead of propagatingundefinedthrough bitwise operations.Files changed
src/core/errors.ts-- newInvalidXRefStreamByteWidthErrorclasssrc/core/parser/PDFXRefStreamParser.ts-- validation + bounds checkingtests/core/parser/PDFXRefStreamParser.spec.ts-- 2 new test casesTest plan
/W [100, 100, 100]throws descriptive error/W [1, 4, 0](valid widths) does not throw