Bugfix and optimize GetStartXrefPosition#1036
Merged
BobLd merged 2 commits intoUglyToad:masterfrom May 13, 2025
Merged
Conversation
The bugfix was the important part but the optimization is pretty nice too. - Bugfix: If startxref was found so far back (eg in the very beginning which can be the case for Linearized PDFs) that we ended up setting actualStartOffset to 0 then the loop would exit immediately without actually searching that part. - Optimization: GetStartXrefPosition would search for startxref in the last 2048 bytes and then double that search-range (looking back 4096, 8192, etc bytes) to look for startxref until the entire file was searched. This was rather inefficient since each step would search the same parts over and over again. This has been changed to properly search (still increasingly larger) chunks that doesn't overlap. On a test of 5000 PDFs that reduced their load-time by 10%. - Change: No need for the exception to say that startxref couldn't be found "in the last 2048 characters" since the entire file was searched anyway.
BobLd
approved these changes
May 13, 2025
Contributor
Author
|
Wonderful, thanks @BobLd 👍 |
Collaborator
|
@ricflams if you have document samples that where failing before your fix, feel free to share them here, im happy to add tests. Or feel free to add a PR with tests |
Contributor
Author
|
@BobLd, here's one example of a file with some trailing html that's would cause the former backwards-search to fail finding the startxref - it would wrongfully skip searching the first about 50K of the file. |
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.
The bugfix was the important part but the optimization is pretty nice too.