Skip to content

BUG: Reject a non-positive number of copies - #4012

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:validate-num-copies
Aug 26, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:validate-num-copies

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

/NumCopies is written through without a check:

>>> viewer_preferences.num_copies = 0
>>> viewer_preferences.num_copies
0
>>> viewer_preferences.num_copies = -5
>>> viewer_preferences.num_copies
-5

So a document can ask a viewer to print no copies, or a negative number of them.

The name-valued preferences beside it already refuse a value outside their allowed set and report it the same way, so this uses the same message shape. _set_int backs only num_copies, so nothing else is affected.

Reverting the change fails the three new tests

@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 98.00%. Comparing base (38170a2) to head (e0b000f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4012   +/-   ##
=======================================
  Coverage   98.00%   98.00%           
=======================================
  Files          57       57           
  Lines       11124    11126    +2     
  Branches     2086     2087    +1     
=======================================
+ Hits        10902    10904    +2     
  Misses        124      124           
  Partials       98       98           

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

Why is 0 no valid value here?

@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

No good reason, you're right. The spec gives no lower bound for /NumCopies, only a typical default of one, so a reader that sees 0 falls back to its own default - and set_page_label already treats a start of 0 as "not set" rather than refusing it.

Narrowed to negatives only, which is the part a reader genuinely cannot interpret. Rebased at the same time since this one had the same test-file conflict.

@stefan6419846

Copy link
Copy Markdown
Collaborator

We have the next conflict after the last merge.

/NumCopies was written through without a check, so a negative value was stored
just as readily as a real count and no reader can interpret it.

Zero stays allowed: the spec gives no lower bound, only a typical default of
one, so a reader that sees it falls back to its own default. set_page_label
treats a start of zero the same way.
@stefan6419846
stefan6419846 merged commit 2955949 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