Skip to content

fix(parser): handle malformed xref entries gracefully - #1803

Open
Junio243 wants to merge 2 commits into
Hopding:masterfrom
Junio243:fix/malformed-xref-entries
Open

Junio243 wants to merge 2 commits into
Hopding:masterfrom
Junio243:fix/malformed-xref-entries

Conversation

@Junio243

@Junio243 Junio243 commented Nov 28, 2026 •

Copy link
Copy Markdown

Fixes #1802.

  • Stop parsing a classic xref entry when its generation number is missing or non-numeric, allowing the existing recovery path to rebuild the document.
  • Add regression tests for missing and non-numeric generation fields.

Validation:

  • Both new tests fail on unmodified upstream/master with NumberParsingError and pass with this change.
  • yarn typecheck passed.
  • yarn test passed: 65 suites, 622 tests (620 existing + 2 new).

When parsing classic xref tables, malformed entries (missing generation
number, garbage data) would throw 'Failed to parse number' errors.
This fix wraps the parsing in try-catch and skips malformed entries,
allowing pdf-lib to load PDFs with minor xref corruption.

Closes Hopding#1802
Copilot AI balanced review requested due to automatic review settings November 28, 2026 03:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDFDocument.load throws "Failed to parse number" on a malformed entry in a classic xref table

2 participants