Skip to content

ROB: Handle a TD operator with a missing or non-numeric ty - #4233

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:td-non-numeric-operands
Oct 21, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:td-non-numeric-operands

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

A TD operator sets the leading to -ty before moving like Td. With a name as ty (/X /Y TD), negating it raised TypeError: bad operand type for unary - in both plain and layout mode, and in layout mode a TD with one operand or none raised IndexError.

The leading is now only set when ty is a number; otherwise it is left unchanged, like a non-numeric TL, and the translation is handled as for Td. A valid TD behaves as before (covered by test_layout_mode_uncommon_operators).

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.19%. Comparing base (cd3e646) to head (db8fc2b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4233   +/-   ##
=======================================
  Coverage   98.19%   98.19%           
=======================================
  Files          59       59           
  Lines       11850    11851    +1     
  Branches     2228     2229    +1     
=======================================
+ Hits        11636    11637    +1     
  Misses        118      118           
  Partials       96       96           

☔ 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 94533a4 into py-pdf:main Oct 21, 2026
21 checks passed
stefan6419846 pushed a commit that referenced this pull request Oct 31, 2026
* ROB: Tolerate extra operands before Tm/cm in layout mode

A matrix operator consumes the 6 operands nearest to it; values
left on the operand stack before those (malformed content streams)
overflowed TextStateManager.new_transform() and raised TypeError
in layout mode text extraction.

Complete the matrix with only the last 6 operands in
_complete_matrix and add_cm, mirroring the tolerance already in
place for missing/non-numeric TD and Tz operands (#4232, #4233).

Fixes #4283

Co-authored-by: rahul05ranjan <[email protected]>

* Add layout-mode tests for extra operands before Tm/cm

Co-authored-by: rahul05ranjan <[email protected]>

---------

Co-authored-by: rahul05ranjan <[email protected]>
stefan6419846 added a commit that referenced this pull request Oct 31, 2026
* ROB: Tolerate extra operands before Tm/cm in layout mode

A matrix operator consumes the 6 operands nearest to it; values
left on the operand stack before those (malformed content streams)
overflowed TextStateManager.new_transform() and raised TypeError
in layout mode text extraction.

Complete the matrix with only the last 6 operands in
_complete_matrix and add_cm, mirroring the tolerance already in
place for missing/non-numeric TD and Tz operands (#4232, #4233).

Fixes #4283

Co-authored-by: rahul05ranjan <[email protected]>

* Fix set_page_label TypeError when start=None

The start parameter is annotated Optional[int] and its validation
accepts None as "not set", but _set_page_label used ,
which treats None as a value to write and crashes in NumberObject.

Only write /St when a concrete non-zero start was provided.

Fixes #4285

Co-authored-by: rahul05ranjan <[email protected]>

* Add tests for set_page_label with start=None

Co-authored-by: rahul05ranjan <[email protected]>

* Update tests/test_writer.py

* Update tests/test_writer.py

---------

Co-authored-by: rahul05ranjan <[email protected]>
Co-authored-by: Stefan <[email protected]>
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