Skip to content

fix: handle off-by-one xref subsection start in malformed PDFs#38

Merged
Mythie merged 2 commits intoLibPDF-js:mainfrom
redsuperbat:fix/xref-off-by-one
Feb 28, 2026
Merged

fix: handle off-by-one xref subsection start in malformed PDFs#38
Mythie merged 2 commits intoLibPDF-js:mainfrom
redsuperbat:fix/xref-off-by-one

Conversation

@redsuperbat
Copy link
Contributor

Some PDFs have a malformed xref table where the subsection header reports the starting object number as 1 instead of 0, while the entries clearly start at object 0 (free list head with gen 65535). This shifted all object resolutions by one, causing wrong page count and infinite loops in extractPages.

  • Detect and correct the off-by-one in xref subsection parsing
  • Add cycle detection to ObjectCopier.getInheritedAttribute as defense-in-depth
  • Add unit test for xref correction and integration test with fixtures

Some PDFs have a malformed xref table where the subsection header
reports the starting object number as 1 instead of 0, while the
entries clearly start at object 0 (free list head with gen 65535).
This shifted all object resolutions by one, causing wrong page count
and infinite loops in extractPages.

- Detect and correct the off-by-one in xref subsection parsing
- Add cycle detection to ObjectCopier.getInheritedAttribute as
defense-in-depth
- Add unit test for xref correction and integration test with fixtures
@vercel
Copy link
Contributor

vercel bot commented Feb 26, 2026

@redsuperbat is attempting to deploy a commit to the mythie's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Mythie Mythie merged commit 5c2d6b3 into LibPDF-js:main Feb 28, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants