Use latest version of objects from object streams (#1) #169
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.
Previously, when an object was parsed from an object stream and it referenced an indirect object, it'd pull the current version of that object at parse time. This means if you have an object stream that declares updated versions of two objects, the first of which references the second, the first object will have the incorrect old value for the second object. For example, if the content of an object stream is something like (formatted for clarity, and with probably incorrect offsets):
The object stream here defines both objects (1, 0) and (2, 0). If this is an incremental update for (2, 0), the previous version of the code would make /Kids for (1, 0) the previous version of (2, 0). This was manifesting in several PDFs we found in the wild as incorrect page counts. The PDFs had added additional pages in incremental updates, and the old /Pages objects with incorrect kids were getting used.
I've ran this branch against all pdfrw tests and they all still pass. This includes roundtrips for lots of existing PDFs, so I'm fairly confident that it's not going to break the status quo. It also fixes several of the PDFs that broke for us on pdfrw master.