Skip to content

ROB: Do not crash when a destination tree node entry is not an array - #4039

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:named-destination-node-not-an-array
Sep 3, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:named-destination-node-not-an-array

Conversation

@RavSinghChandan

@RavSinghChandan RavSinghChandan commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

A name tree node holds its entries under /Names or /Kids, and both are read straight
into a cast without checking what came back. If either is not an array, reading the
named destinations crashes: /Names as a number fails on len(), /Names as a string
fails on get_object(), and /Kids as a number fails when the loop tries to iterate it.

This sits right next to the /Dests guard from #4020 and behaves the same way - the
entry is logged and no destinations are returned, instead of the whole document
becoming unreadable.

Tests cover the container itself being wrong. The existing non_array_value test
already covers a bad element inside a valid array, so that case is untouched.

I could not run the tests that download the corpus locally; the offline suite passes,
1238 tests.
Used Claude (Opus) to help locate and patch this; I reviewed and tested the change.

@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.05%. Comparing base (939ae0c) to head (c248d3b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4039   +/-   ##
=======================================
  Coverage   98.04%   98.05%           
=======================================
  Files          57       57           
  Lines       11225    11232    +7     
  Branches     2114     2116    +2     
=======================================
+ Hits        11006    11013    +7     
  Misses        122      122           
  Partials       97       97           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stefan6419846

Copy link
Copy Markdown
Collaborator

As a general consideration: Are all of these cases issues on our side or spec violations? I am asking because in theory we would have to differentiate between strict and non-strict mode if there are spec violations.

@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

They are spec violations - §7.9.6 says a name tree node's /Names and /Kids shall be
arrays, so anything else is a broken file rather than something we are misreading.

I kept them as warnings rather than adding a strict branch because the surrounding
code already treats §7.9.6 violations that way. A few lines further down, a /Names
key that is not a string is skipped with no strict check at all, and the /Dests
guard just above from #4020 warns and returns in both modes. Doing it differently
here would make the same function behave two ways for the same class of problem.

Happy to raise these in strict mode if you would prefer that, but it felt like a
question for all of the name tree handling at once rather than something to change
in this PR alone. Whichever you prefer is fine with me.

@stefan6419846
stefan6419846 merged commit 816b120 into py-pdf:main Sep 3, 2026
21 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