Skip to content

ROB: Do not crash when the page label kids are not an array - #4102

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:page-labels-malformed-kids
Sep 18, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:page-labels-malformed-kids

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

index2label casts the /Kids entry of a number tree to a list of dictionaries and
iterates it:

kids = cast(list[DictionaryObject], number_tree["/Kids"])
for kid in kids:
    limits = kid.get("/Limits", NullObject()).get_object()

The cast has no effect at runtime, so a file where /Kids holds a string raises
'AttributeError: str object has no attribute get' from reader.page_labels, and
a file whose kids array holds a number raises the same error for the element.

Both now take the fallback the function already uses for a /PageLabels entry it
cannot read: the malformed entry is reported and the page position is returned.
This follows #4022, which added the same handling one level up when /PageLabels
itself is not a dictionary.

The third test is a regression guard rather than a fix: an indirect kids array
and an indirect kid already resolved correctly, and .get_object() keeps that
working now that the cast is gone.

Offline suite passes, 1379 tests.

Used Claude (Opus) to help locate and patch this; I reviewed and tested the change.

index2label casts the /Kids entry of a number tree to a list of dictionaries
and iterates it, so a file where that entry holds a string raised
'AttributeError: str object has no attribute get' from reader.page_labels, and
a file whose kids array holds anything other than a dictionary raised the same
error for the element.

Both cases now take the fallback the function already uses for a /PageLabels
entry it cannot read: the malformed entry is reported and the page position is
returned.
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.11%. Comparing base (095d5af) to head (e76448a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4102   +/-   ##
=======================================
  Coverage   98.11%   98.11%           
=======================================
  Files          59       59           
  Lines       11532    11539    +7     
  Branches     2152     2154    +2     
=======================================
+ Hits        11315    11322    +7     
  Misses        123      123           
  Partials       94       94           

☔ 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
stefan6419846 merged commit df5397d into py-pdf:main Sep 18, 2026
20 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