Fix #1601: guard against corrupt object-stream references in xref streams - #1602
Open
andreasrosdalw wants to merge 1 commit into
Open
Fix #1601: guard against corrupt object-stream references in xref streams#1602andreasrosdalw wants to merge 1 commit into
andreasrosdalw wants to merge 1 commit into
Conversation
…xref streams A cross-reference stream's type 2 (compressed object) entry can reference an object-stream number that does not correspond to any parsed object (e.g. a corrupt/malformed xref stream where the reference is far outside the actual object range). PdfReader.readDocObj() looked up that object number via xrefObj.get(n) without any bounds or type check, so a malformed PDF could crash the reader with a raw IndexOutOfBoundsException (or ClassCastException) instead of a handled parse error. Skip such entries the same way getPdfObject(int) already tolerates out-of-range indices, so a single corrupt compressed-object reference no longer prevents the rest of an otherwise valid document from parsing.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 14 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
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
PdfReadercould throw a rawIndexOutOfBoundsException("Index 57407 out of bounds for length 899") when parsing a PDF whose cross-reference stream has a type 2 (compressed object) entry pointing at an object-stream number outside the document's actual object range.PdfReader.readDocObj(), theobjStmMarkprocessing loop callsxrefObj.get(n)with no bounds or type check, unlikegetPdfObject(int)a few hundred lines above, which already guardsidx < 0 || idx >= xrefObj.size(). A corrupt/malformed xref stream can set that object-stream number to an arbitrary value (e.g. via a truncated or hand-edited PDF), and the unguarded.get(n)throws instead of failing gracefully.objStmMarkentry when its key is out of range or does not actually resolve to aPRStream, mirroring the existing tolerant behavior ofgetPdfObject(int). A single corrupt compressed-object reference no longer prevents the rest of an otherwise valid document from parsing.