Skip to content

ROB: Do not crash when the font /FirstChar is not a number - #4163

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:font-first-char-not-a-number
Oct 7, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:font-first-char-not-a-number

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

_collect_tt_t1_character_widths reads /FirstChar and compares it with 0 before
enumerating the widths:

first_char = pdf_font_dict.get("/FirstChar", 0)
if first_char < 0:

A file storing null, a name or a string there raises
"TypeError: '<' not supported between instances of 'NullObject' and 'int'"
out of extract_text(extraction_mode="layout").

A /FirstChar that is not a number is now reported and the widths are skipped,
the same way a negative /FirstChar is already handled. A float such as 65.0 is
used as an integer.

Full suite passes locally, 1810 tests, and the change is fully covered.

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

@stefan6419846 stefan6419846 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review the merge conflicts.

@RavSinghChandan
RavSinghChandan force-pushed the font-first-char-not-a-number branch from 1d4606d to 5fa1b44 Compare October 6, 2026 16:05
@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

Rebased onto main after the _font move in #4162; the conflicts are resolved and the test now lives in tests/generic/test_font.py.

@codecov

codecov Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.12%. Comparing base (294a4a0) to head (5fa1b44).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4163   +/-   ##
=======================================
  Coverage   98.12%   98.12%           
=======================================
  Files          59       59           
  Lines       11600    11604    +4     
  Branches     2175     2176    +1     
=======================================
+ Hits        11383    11387    +4     
  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 3ecbbc5 into py-pdf:main Oct 7, 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