BUG: Fix stale object cache from non-authoritative object streams#3698
Merged
stefan6419846 merged 5 commits intopy-pdf:mainfrom Mar 26, 2026
Merged
Conversation
The batch-parse optimization (added in py-pdf#3677) caches every object found when decompressing an object stream. The guard intended to skip overridden objects checked `obj_num in self.xref_objStm`, but this passes for any compressed object — not just ones that belong to the current stream. In incrementally-updated PDFs, the same object can appear in multiple object streams across revisions (per the PDF 1.7 spec, §7.5.6). The xref designates one stream as authoritative. Decompressing a stale stream (e.g. to read a co-located AcroForm dict) would cache the old version of the object, shadowing the current one. Fix: only cache when `xref_objStm` points the object at the stream being decompressed. Closes py-pdf#3697 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use Union[str, bytes] instead of str | bytes since the file does not use `from __future__ import annotations`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Looks like a transient failure downloading one of the test inputs. Maybe this test is known to be flaky? I don't have permission to re-trigger the CI job , unfortunately |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3698 +/- ##
=======================================
Coverage 97.43% 97.43%
=======================================
Files 55 55
Lines 10008 10009 +1
Branches 1839 1839
=======================================
+ Hits 9751 9752 +1
Misses 149 149
Partials 108 108 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3697
The batch-parse optimization (#3677) caches every object found when decompressing an object stream. The guard intended to skip overridden objects checked
obj_num in self.xref_objStm, but this passes for any compressed object — not just ones that belong to the current stream.In incrementally-updated PDFs, the same object can appear in multiple object streams across revisions (per the PDF 1.7 spec, §7.5.6). The xref designates one stream as authoritative. Decompressing a stale stream (e.g. to read a co-located AcroForm dict) would cache the old version of the object, shadowing the current one.
In practice this causes filled-in form field values to silently disappear when reading PDFs saved by form-filling software.
Fix: one-line change — only cache when
xref_objStmpoints the object at the stream being decompressed.