Skip to content

ROB: Reject too few values when setting a page box - #4009

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:validate-page-box-setter
Aug 26, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:validate-page-box-setter

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

page.mediabox = ArrayObject([0, 0]) is accepted, but reading the box back raises:

>>> page.mediabox = ArrayObject([0, 0])
>>> page.mediabox
ValueError: Expected four values for /MediaBox, got 2: [0, 0]

So a page can be written with a box that cannot be read back.

The getter warns and truncates when there are more than four values, for backwards compatibility with files pypdf itself once wrote, so the setter keeps accepting those and only refuses the case the getter cannot handle. Writing through page[NameObject("/MediaBox")] directly is untouched.

Applies to all five boxes. Reverting the change fails the ten new tests

page.mediabox = ArrayObject([0, 0]) was accepted, but reading the box back
raises ValueError because a rectangle cannot be built from two numbers, so the
page could be written and not read.

The getter warns and truncates when there are more than four values, for
backwards compatibility with files pypdf itself once wrote, so the setter
keeps accepting those and only refuses the case the getter cannot handle.
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.98%. Comparing base (2d21458) to head (ebae60f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4009   +/-   ##
=======================================
  Coverage   97.98%   97.98%           
=======================================
  Files          57       57           
  Lines       11120    11122    +2     
  Branches     2084     2085    +1     
=======================================
+ Hits        10896    10898    +2     
  Misses        125      125           
  Partials       99       99           

☔ 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 8687d25 into py-pdf:main Aug 26, 2026
30 of 34 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