BUG: PageObject.scale() scales media box incorrectly (#3487)#3489
BUG: PageObject.scale() scales media box incorrectly (#3487)#3489stefan6419846 merged 7 commits intopy-pdf:mainfrom
Conversation
|
I'm not sure if I'm required to create a test for this fix. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3489 +/- ##
=======================================
Coverage 97.09% 97.09%
=======================================
Files 56 56
Lines 9664 9664
Branches 1750 1750
=======================================
Hits 9383 9383
Misses 168 168
Partials 113 113 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I have not been aware that the faulty commit would not have proper tests, thus I did not require a new one. With the current regression, we should add one to ensure this does not break again.
This is a very strange side effect, as the boxes all look correct: @pytest.mark.enable_socket
def test_scale_by():
"""Tests for #3487"""
url = "https://github.com/user-attachments/files/22685841/input.pdf"
name = "issue3487.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
original_box = RectangleObject((0, 0, 595.275604, 841.88974))
expected_box = RectangleObject((0.0, 0.0, 297.637802, 420.94487))
for page in reader.pages:
assert page.artbox == original_box
assert page.bleedbox == original_box
assert page.cropbox == original_box
assert page.mediabox == original_box
assert page.trimbox == original_box
page.scale_by(0.5)
assert page.artbox == expected_box
assert page.bleedbox == expected_box
assert page.cropbox == expected_box
assert page.mediabox == expected_box
assert page.trimbox == expected_boxThus, we need a rendering test with Ghostscript here to actually detect this bug (which has already been fixed in the past in #1314 - without adding a test). |
|
If I am not mistaken, the added test is not sufficient, as running it against main is successful as well, not providing any benefits (as outlined in my comment as well). We have to add a test similar to the discussions in the issue by comparing the rendering results with Ghostscript, as mentioned in my comment as well (examples are already available for watermarking for example). |
Ah, the usage of Ghostscript exceeds my current skill level for now and I don't know, when I have the time available to look into that for a proper test. 🤔 |
|
I have added a Ghostscript-based test. After resolving the open discussion, this should be ready for merging. |
## What's new ### Security (SEC) - Allow limiting size of LZWDecode streams (#3502) by @stefan6419846 - Avoid infinite loop when reading broken DCT-based inline images (#3501) by @stefan6419846 ### Bug Fixes (BUG) - PageObject.scale() scales media box incorrectly (#3489) by @Nid01 ### Robustness (ROB) - Fail with explicit exception when image mode is an empty array (#3500) by @stefan6419846 [Full Changelog](6.1.2...6.1.3)
Closes py-pdf#3487. --------- Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
## What's new ### Security (SEC) - Allow limiting size of LZWDecode streams (py-pdf#3502) by @stefan6419846 - Avoid infinite loop when reading broken DCT-based inline images (py-pdf#3501) by @stefan6419846 ### Bug Fixes (BUG) - PageObject.scale() scales media box incorrectly (py-pdf#3489) by @Nid01 ### Robustness (ROB) - Fail with explicit exception when image mode is an empty array (py-pdf#3500) by @stefan6419846 [Full Changelog](py-pdf/pypdf@6.1.2...6.1.3)
Partly undo d89fb78#diff-153e5cee71ddf471246ff5c0e198345f005942a540a8f39297736f0b620d631dR1587-R1592 since the changed order of updates to the page boundaries results in wrongly scaled pdfs.