BUG: Avoid accessing invalid page when inserting blank page under some conditions#3529
BUG: Avoid accessing invalid page when inserting blank page under some conditions#3529j-t-1 wants to merge 20 commits intopy-pdf:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3529 +/- ##
=======================================
Coverage 97.36% 97.36%
=======================================
Files 55 55
Lines 9940 9945 +5
Branches 1822 1824 +2
=======================================
+ Hits 9678 9683 +5
Misses 152 152
Partials 110 110 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
stefan6419846
left a comment
There was a problem hiding this comment.
- Please add a test for an out-of-bounds index.
- What happens if the width is 0 or negative?
- Please update the title to reflect what the actual bug was - currently, it is not obvious which logic is meant or what was wrong.
If |
|
The specific case from #3337 (comment) is still not tested? |
|
Shall I do this? |
Add a test for an out-of-bounds index does this I thought. Have I not done the test correctly? |
|
If would use
Have you tested the behavior without your change to the logic? Did it fail? If not, your change most likely does not yet cover the desired case. |
No. So I do the same check on the old code and make sure it fails? |
|
Yes. This is the usual way you should assert that your tests are correct. |
Thanks.
Will do. Is this the only outstanding now? |
As far as I can currently see, yes. We probably want to cover both variants (setting only width, setting only height), although only one case has previously been broken, but it makes the tests more consistent. |
|
The old code: Has this error: Because the |
|
But we still do not have a test for the previous wrong code mentioned before? page = writer.insert_blank_page(width=None, height=42, index=len(writer.pages)) |
Good call. I think the code is incorrect, as it fails this test. |
width and height are now treated symmetrically, and updated only if they are not provided.
|
What do you want done |
|
We could theoretically remove the condition completely and would use the last page in this case (which should be documented and tested) - or raise an error as this is a user error. I would probably go with a user error, as this should never be what the user wants. |
Good call. I will amend so it raises an error. |
|
@stefan6419846 this got stuck in the tests, please could you re-run it if you have that option? |
|
Something is odd with the PyPy 3.11 tests lately, as they regularly get stuck. I have not yet found a pattern except re-triggering it (possibly after a rebase) and hoping. |
width and height are now treated symmetrically and updated only if they are not provided.