Skip to content

Conversation

@stefan6419846
Copy link
Collaborator

There are incremental PDF files in the wild which define a too small /Size in the final part.

I have initially seen this with an incremental PDF file where no object has been updated and the /Size set to 1, although the previous /Size would be 24. During analysis, it turned out that loading the same PDF file in incremental mode would not fail, but with /Size 2 (due to subtracting 1 in this path).

I could not see any negative side effects when changing this for non-incremental writer mode in pypdf, thus the assertion appears to be too strict here. Instead, replace the assertion with a proper error/warning message and report proper errors on an index error when attempting to flatten the faulty PDF in incremental mode.

@codecov
Copy link

codecov bot commented Oct 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.09%. Comparing base (54c0dd7) to head (b72444a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@ ## main #3495 +/- ## ======================================= Coverage 97.09% 97.09% ======================================= Files 56 56 Lines 9658 9664 +6 Branches 1748 1750 +2 ======================================= + Hits 9377 9383 +6  Misses 168 168 Partials 113 113 

☔ View full report in Codecov by Sentry.
📢 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 16c4c44 into py-pdf:main Oct 16, 2025
16 checks passed
@stefan6419846 stefan6419846 deleted the incremental-wrong-size branch October 16, 2025 12:30
stefan6419846 added a commit that referenced this pull request Oct 19, 2025
## What's new ### Bug Fixes (BUG) - Fix handling of zero-length StreamObject (#3485) by @Likend ### Robustness (ROB) - Deal with wrong size for incremental PDF files (#3495) by @stefan6419846 - Improve handling for malformed cross-reference tables (#3483) by @stefan6419846 ### Developer Experience (DEV) - Use released Python 3.14 by @stefan6419846 - Use Mapping instead of dict in type hint of update_page_form_field_values (#3490) by @stefan6419846 [Full Changelog](6.1.1...6.1.2)
OpenNingia pushed a commit to OpenNingia/pypdf that referenced this pull request Oct 23, 2025
OpenNingia pushed a commit to OpenNingia/pypdf that referenced this pull request Oct 23, 2025
## What's new ### Bug Fixes (BUG) - Fix handling of zero-length StreamObject (py-pdf#3485) by @Likend ### Robustness (ROB) - Deal with wrong size for incremental PDF files (py-pdf#3495) by @stefan6419846 - Improve handling for malformed cross-reference tables (py-pdf#3483) by @stefan6419846 ### Developer Experience (DEV) - Use released Python 3.14 by @stefan6419846 - Use Mapping instead of dict in type hint of update_page_form_field_values (py-pdf#3490) by @stefan6419846 [Full Changelog](py-pdf/pypdf@6.1.1...6.1.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant