Skip to content

ROB: Fall back to the page position when the page label /Nums is not an array - #4271

Merged
stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:page-label-nums-not-array
Oct 29, 2026
Merged

stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:page-label-nums-not-array

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

reader.page_labels raised TypeError: object of type 'NumberObject' has no len() when the /Nums entry of /PageLabels is not an array, for example << /Nums 1 >>. index2label() already warns and falls back to the page position when /PageLabels is not a dictionary or /Kids is not an array, but get_label_from_nums() called len() on /Nums without a check (index2labels() from #4251 already sends this case page by page to index2label()).

get_label_from_nums() now does the same for /Nums: it logs "Page label numbers are not an array: ..." and returns the page position. Added test_index2label__nums_not_an_array next to test_index2label__kids_not_an_array, with the same number, dictionary and string cases.

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.54%. Comparing base (815f287) to head (8ca5b3e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4271   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files          59       59           
  Lines       11992    11995    +3     
  Branches     2267     2268    +1     
=======================================
+ Hits        11817    11820    +3     
  Misses         95       95           
  Partials       80       80           

☔ 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.

Comment thread tests/test_page_labels.py Resolved
@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

No good reason. I have changed it to pass /Nums when creating the dictionary.

@stefan6419846
stefan6419846 merged commit 1b8a064 into py-pdf:main Oct 29, 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