Repository navigation
Simplify stream boundary recovery - #561
Merged
Merged
Conversation
Collapse the three recovery entry points into one recover_stream_range method with thin wrappers that differ only in how /Length is read, and replace the parser save/restore dance with pure functions over the input. With a stale /Length hint, the terminator scan now stops at the first valid candidate past the declared boundary instead of scanning to the end of the file, since every later candidate lies farther away. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Summary
recover_stream_range(length: Option<usize>).parse_stream_recoveringandparse_stream_recovering_direct_lengthbecome thin wrappers that differ only in how/Lengthis read.skip_stream_recoveringis removed; the linear object scanner calls the core method directly, so it no longer copies the stream.StreamTerminator { start, end }type./Lengthhint, the terminator scan stops at the first valid candidate past the declared boundary instead of scanning to the end of the file, since every later candidate lies farther away. Previously, recovering a document whose streams had wrong lengths took time quadratic in the file size.endstreawith one optionalm.endstreamstays required.endobjmarks where the object ends, but onlyendstreammarks where the data ends, and requiring both is the main guard against matches inside binary stream data.Apart from the speed fix, parsing gives the same results.
stream_recovery.rsgoes from 334 to 233 lines.Test plan
cargo test -p pdf-parser -p pdf-documentcargo clippy: no new warnings compared with the base commit🤖 Generated with Claude Code