Skip to content

Fall back to the /Catalog dictionary when a PDF file has no trailer - #22309

Closed
andrewfader wants to merge 4 commits into
mozilla:masterfrom
andrewfader:xref-recover-catalog
Closed

andrewfader wants to merge 4 commits into
mozilla:masterfrom
andrewfader:xref-recover-catalog

Conversation

@andrewfader

Copy link
Copy Markdown
Contributor

When a file is truncated before its XRef table and trailer, e.g. an incomplete download, XRef.indexObjects finds no trailer dictionary and throws "Invalid PDF structure.", even though the /Catalog dictionary and pages may be intact.

This extends the fallback from issue 18986: if no dictionary with a /Root entry is found, the first /Catalog dictionary is used as the /Root.

The new unit test fails without the patch with "Invalid PDF structure.".

A file truncated before its XRef table and trailer, e.g. an incomplete download, may still contain its /Catalog dictionary. Rather than failing with "Invalid PDF structure.", use it as the /Root when no trailer dictionary can be found.

@Snuffleupagus Snuffleupagus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you please provide a real-world example of a (corrupt) PDF that this patch fixes?

@andrewfader

Copy link
Copy Markdown
Contributor Author

Yes, I can. None of these issues is theoretical: I will find representative PDFs and get back to you. Some of the PDFs might be confidential/proprietary, so I have to possibly contrive an example PDF based on the real one.

andrew-fader-wbd and others added 2 commits October 27, 2026 16:33
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@andrewfader
andrewfader marked this pull request as draft October 27, 2026 20:53
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@andrewfader
andrewfader marked this pull request as ready for review October 27, 2026 21:00
@andrewfader
andrewfader marked this pull request as draft October 27, 2026 21:02
@Snuffleupagus

Copy link
Copy Markdown
Collaborator

Sorry, but what appears to be (entirely?) AI generated patches for issues that have never actually been reported before isn't a good use of human reviewer time.

If these are real problems, please submit proper issues (filling out the ISSUE_TEMPLATE correctly) that include the affected PDFs and/or runnable test-cases.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants