Skip to content

ROB: Do not crash when the font resources are not a dictionary - #4138

Merged
stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:font-resources-not-a-dict
Oct 3, 2026
Merged

stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:font-resources-not-a-dict

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

Reopening the fix from #4043, which I closed earlier to stay within one or two
open PRs. Same idea, with three gaps closed.

If a page's /Resources has a /Font entry that is not a dictionary (a number,
string or array), extract_text() fails with
TypeError: 'NumberObject' object is not iterable. It happens in plain mode and
in layout mode. A null /Font crashed the same way.

This adds _get_font_resources() next to _get_page_resources() and follows the
same pattern. Null or missing gives an empty dictionary with no warning. Any
other non-dictionary value logs "Font resources are not a dictionary" and gives
an empty dictionary. Both the plain and layout extraction paths now use it.

Compared to #4043: null is now treated as absent instead of malformed, the
layout-mode path is fixed too, and there is a test for the null case. The normal
path is already covered by test_extract_text__resources_is_a_dictionary.

The tests fail without the change and pass with it. Locally the only failures
are tests whose files are missing from tests/pdf_cache, and those fail the same
way on main.

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

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.12%. Comparing base (59c1d74) to head (1512f83).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4138      +/-   ##
==========================================
+ Coverage   98.10%   98.12%   +0.01%     
==========================================
  Files          59       59              
  Lines       11563    11572       +9     
  Branches     2163     2161       -2     
==========================================
+ Hits        11344    11355      +11     
+ Misses        124      123       -1     
+ Partials       95       94       -1     

☔ 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.py Resolved
@stefan6419846
stefan6419846 merged commit b27fd18 into py-pdf:main Oct 3, 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