Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine reconstruction of xref tables and trailers #1196

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

m-holger
Copy link
Contributor

@m-holger m-holger commented May 7, 2024

When xref table recovery is triggered by failure to find a valid trailer, accept the last valid trailer rather than the first valid trailer.

Copy link

codecov bot commented May 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.33%. Comparing base (973edb4) to head (5de67d4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1196      +/-   ##
==========================================
- Coverage   93.34%   93.33%   -0.01%     
==========================================
  Files         299      299              
  Lines       32997    33000       +3     
  Branches     4037     4038       +1     
==========================================
+ Hits        30801    30802       +1     
- Misses       2196     2198       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@m-holger
Copy link
Contributor Author

m-holger commented May 7, 2024

xref table creation and reconstruction raises a number of questions, including:

  1. QPDF objects without a root object are generally unusable and will eventually throw a damagedPDF exception. Would it make sense to check for the root object early?

  2. Should a trailer without /Root key be accepted as a valid trailer (which would necessarily end in a damagedPDF exception)? It would seem to make sense to treat such trailers as damaged and try to find a better candidate.

  3. qpdf generates a warning if the highest object number in the xref table does not match the trailer /Size key. The spec states

     Any object in a cross-reference section whose number is greater than this
     value shall be ignored and defined to be missing by a conforming reader.
    

    Should qpdf remove objects with ids >= /Size from the xref table?

Change first xref stream dictionary to point to an invalid root in order
to detect failure to recover the last valid trailer.
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.

None yet

1 participant