Skip to content

ROB: Skip truncated bfrange and bfchar lines in process_cm_line - #3829

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
metsw24-max:cmap-skip-broken-lines
Jun 8, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
metsw24-max:cmap-skip-broken-lines

Conversation

@metsw24-max

Copy link
Copy Markdown
Contributor

Truncated /ToUnicode lines crash text extraction
A beginbfrange line with fewer than three tokens makes parse_bfrange read past the split list, and a beginbfchar line with a non-hex source token raises out of parse_bfchar. The bfrange call only caught binascii.Error and the bfchar call caught nothing, so a crafted /ToUnicode CMap takes down extract_text on the page. Widened both to skip the broken line and warn, same as the existing handling. LimitReachedError is a PyPdfError not a ValueError so the mapping size cap still propagates.

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.73%. Comparing base (dad0f5e) to head (6ba786c).
⚠️ Report is 180 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3829   +/-   ##
=======================================
  Coverage   97.73%   97.73%           
=======================================
  Files          55       55           
  Lines       10421    10423    +2     
  Branches     1932     1932           
=======================================
+ Hits        10185    10187    +2     
  Misses        130      130           
  Partials      106      106           

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

Thanks for the PR.

Could you please remember to follow our contribution guidelines regarding PR titles?

Additionally, why can we drop binascii.Error in favor of ValueError and IndexError?

@metsw24-max metsw24-max changed the title skip truncated bfrange and bfchar lines in process_cm_line ROB: Skip truncated bfrange and bfchar lines in process_cm_line Jun 5, 2026
@metsw24-max

Copy link
Copy Markdown
Contributor Author

Sorted the title with the ROB: prefix, sorry for missing that.

On the exception change: binascii.Error is a subclass of ValueError, so widening to ValueError still catches the non-hex case the old handler covered, nothing is lost there. The IndexError is the new bit, it covers the truncated bfrange where lst[1]/lst[2] index past the split. LimitReachedError is a PyPdfError rather than a ValueError, so the mapping size cap still propagates as before.

@stefan6419846
stefan6419846 merged commit 1f56e9a into py-pdf:main Jun 8, 2026
32 of 35 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