Skip to content

BUG: Keep the generation number of objects in incremental updates - #4484

Open
metsw24-max wants to merge 1 commit into
py-pdf:mainfrom
metsw24-max:incremental-keep-generation
Open

metsw24-max wants to merge 1 commit into
py-pdf:mainfrom
metsw24-max:incremental-keep-generation

Conversation

@metsw24-max

Copy link
Copy Markdown
Contributor

Incremental updates drop the generation number of existing objects

With incremental=True, clone_reader_document_root fetched every source object as generation 0 and _write_increment wrote changed objects back as N 0 obj. An object stored as N 1 obj was therefore missing from the writer or replaced by an older generation 0 version, and changes to it never reached the N 1 R references: filling the two text fields of issue-3553.pdf whose appearances are 325 1 obj and 326 1 obj left the old empty appearance for both pypdf and qpdf, and in tika-976970.pdf the incremental writer returned a page dictionary as /Contents of the second page. The clone now takes the highest generation listed for each number, which is the one the references point to, and the writer keeps and writes it for objects taken from the source.

Notes for review

  • The third /W field of the increment's xref stream is now 2 bytes, as generation numbers can go up to 65535. Files that only use generation 0 should otherwise be written as before.
  • update_page_form_field_values now replaces an existing /AP /N stream through _replace_object, which already keeps the generation.

In incremental mode every object of the source was fetched and written
back as generation 0. An object stored as `N 1 obj` was then missing from
the writer or replaced by an older generation 0 version, and changes to it
were written as `N 0 obj`, which references to `N 1 R` never reach.

Fetch each object with the highest generation listed for its number, keep
that generation for objects taken from the incremental source and write it
in the object header and the xref stream entry of the increment.
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.25%. Comparing base (0da9460) to head (769e654).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4484   +/-   ##
=======================================
  Coverage   99.25%   99.25%           
=======================================
  Files          59       59           
  Lines       12425    12429    +4     
  Branches     2368     2368           
=======================================
+ Hits        12333    12337    +4     
  Misses         38       38           
  Partials       54       54           

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

This branch has not been deployed

No deployments
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.

1 participant