Repository navigation
Restart a ZIP Deflate member near a target: block search, seeded window, overlap proof (RustyGet) - #371
Merged
Conversation
…ow, overlap proof (#363) zipfast::inflate64::restart finds a Deflate restart before a target from the packed bytes of a search region and the known plaintext, written from RFC 1951 and observed behaviour: - stored and dynamic headers at every bit (LEN/NLEN, Kraft-complete code-length code, valid literal/length and distance codes), then fixed-code blocks by probing (inside a fixed block any symbol boundary is a restart; a late result jumps the probe back by its own bits per byte); - a windowless decode of 8 KiB per candidate (known bytes and references before the start) aligned against the plaintext; late and ambiguous candidates are skipped; - an overlap proof: Inflater::seeded (new: window seeded from plaintext, a match past it is Error::Distance) with Inflater::skip_bits must reproduce the plaintext byte for byte from the restart to the target (> one window), for exactly one offset; - the rest decoded to the entry's size and proven by CRC32 of the known prefix plus the rest; NotFound carries a widened plan, never a guess. Wired into open_at: ZIP method 8 (unencrypted) is Layer::ZipDeflate / RestartGrain::DeflateBlocks with Start::Deflate and complete_deflate. Inflater::ignore_final lets the restart decoder disregard a borrowed final bit. Tests in tests/zip_deflate_restart.rs, bench in examples/deflate_restart_bench.rs, method and limits in docs/open-at.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi
Collaborator
Author
|
@codex review |
…on (PR #371 review) - A stream must end exactly at the entry's size: keep stepping at the size and require end-of-stream with no more output (open only inside the restart's own first block); output past the size is Size. - A fit in the known plaintext below the offsets tried makes a winner ambiguous. - CRC32 required by default: RestartError::Unproven unless RestartOptions::allow_unproven. - prove compares only output inside the known plaintext (no underflow at skip == produced). - Work is charged for empty blocks, consumed input, block headers and dynamic table builds, and failed comparisons up to the first mismatch; more than 8 empty blocks in a row reject a candidate. - The held search region is capped at work/8 (4 KiB..MAX_SEARCH) and reported as searched. - DeflatePlan::widened saturates; DeflateRestart::rejected counts failed proofs. - Tests: repeated text, known_base > 0 with and without prefix_crc, empty-block and failed-fit charging, region caps; docs updated, bench rerun. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi
…t asserts (PR #371 review 2) - NotFound's retry is cut to what one search holds and is None once the searched region cannot grow, so following retries never fetches bytes no search scans. - Only a fixed-block probe's first header has its "final" bit ignored; stored and dynamic candidates trust theirs (windowless decode and overlap proof). A probe's first block is stopped at its end, and ends the stream at the size only with no whole packed byte left after it; anything left must decode to a real end. Steps stopped at a block end may make no progress once without counting as truncated. - Tests: retries_never_fetch_bytes_no_search_scans, the_stream_ends_at_the_size (unit); the entry-start fallback must prove, and the capped-region case must be NotFound. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi
Collaborator
Author
|
Review: Codex did not respond (out of usage), so two clean-room subagent reviews took its place, one for hostile input and one for correctness against #363.
Local CI (full, all gates: fmt, clippy ×2, tests ×2, doctests ×2) passed at 8a41846, the exact head, up to date with main fa031ee, on linux x86_64 (rustyget-x86-q), linux arm64 (rustyget-arm-g) and macOS arm64. |
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 #363 (RustyGet#814, prybar#226).
An unencrypted ZIP Deflate member (method 8) can now restart near a target offset instead of only at its start.
Method
NotFound, with a widened retry plan when one is possible. It never guesses.API
zipfast::inflate64::restart:plan,restart,DeflateEntry,RestartOptions,DeflatePlan,DeflateRestart,RestartError,BlockKind,CrcProof.Inflater: addsseeded,skip_bitsandignore_final. A match reaching past the seeded window is an error, never a panic.map: ZIP method 8 is nowLayer::ZipDeflate/RestartGrain::DeflateBlocks.open_atreturnsStart::Deflate,complete_deflateruns the restart, and failures come back asOpenAtError::Deflate.Limits (docs/open-at.md)
Bench (M4, 32 MiB, 1 MiB search region)
Each restart's search took about as long as inflating the whole entry from the start (2–84 ms). The packed bytes fetched were exactly the search region plus the rest of the entry.
Tests
tests/zip_deflate_restart.rs, 12 tests:Clean-room: written from RFC 1951 and observed behaviour only.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi