Repository navigation
Conversation
The CPRES_ZLIB dictionary-sync path can drop the tail of a matched-block insert when the deflate output buffer fills mid-chunk. `compress()` only consumes input until its output buffer is exhausted, but `see_token` called it once per 64 KiB chunk and discarded the unconsumed tail. With pending output already buffered from a preceding `Z_SYNC_FLUSH`, the combined output for a worst-case 0xFFFF byte insert exceeds the prior 65 536 byte reserve, silently corrupting the receiver's dictionary. - Size the output buffer for `AVAIL_OUT_SIZE(0xFFFF) + 16` so the worst-case stored-block plus sync trailer fits in a single pass. - Loop the `compress()` call until the input chunk is drained; surface a hard error if the compressor ever stalls with worst-case obuf capacity already in place. - Preserve the protocol < 31 data-duplicating bug so wire behaviour matches upstream for legacy peers. Mirrors upstream rsync issue #951 against token.c:send_deflated_token().
Owner
Author
|
Superseded by #5520 (UTS Stream-C: "compress-zlib-insert (UTS-18): ZlibTokenEncoder::see_token() called compress(..., Z_SYNC_FLUSH) exactly once per 0xFFFF chunk"). PR #5520 (merged 2026-06-10) already addresses the same upstream rsync#951 root cause in crates/protocol/src/wire/compressed_token/zlib_codec.rs by draining the Sync flush in a loop until input is consumed and the output buffer is partially filled. The fix on master is functionally equivalent to this PR's drain loop; reimplementing the obuf reserve constants over a merged fix would be a competing rewrite rather than a surgical change. Closing as superseded. |
1 of 2 tasks
4 tasks
oferchen
added a commit
that referenced
this pull request
Jun 10, 2026
Records the wire-byte and runtime invariants that govern the delta-transfer codec stack: the upstream-compatible zlib token decoder, the BufferedMap basis-window mapper, and the streaming raw-deflate primitives in the compress crate. Closes the documentation gap left open by the UTS-18 series (BufferedMap fail-loud bounds, window_len clamp, never-shrink) and PR #5535 (URV-1 zlib obuf overflow on matched-block inserts). - New design doc at docs/design/zlib-codec-invariants.md catalogues wire invariants (INSERT / COPY / END token contracts), runtime invariants per code path, the failure-mode -> regression-test table, and fuzz target rationale. - New complementary fuzz target fuzz/fuzz_targets/zlib_token_decode.rs drives CountingZlibDecoder through arbitrary byte sequences under streaming read semantics. Asserts panic-freedom, monotonic byte-counter, and 100x expansion ceiling. Uses only existing crate APIs. - Two new unit tests in crates/compress/src/zlib/tests.rs pin the malformed-INSERT and COPY-past-EOF panic-freedom guarantees at the streaming decoder layer (malformed stored-block NLEN check, post-EOF Ok(0) tail reads). - Wires zlib_token_decode into the nightly fuzz-coverage matrix workflow and the FCV-20.c coverage tracking table.
oferchen
added a commit
that referenced
this pull request
Jun 10, 2026
Records the wire-byte and runtime invariants that govern the delta-transfer codec stack: the upstream-compatible zlib token decoder, the BufferedMap basis-window mapper, and the streaming raw-deflate primitives in the compress crate. Closes the documentation gap left open by the UTS-18 series (BufferedMap fail-loud bounds, window_len clamp, never-shrink) and PR #5535 (URV-1 zlib obuf overflow on matched-block inserts). - New design doc at docs/design/zlib-codec-invariants.md catalogues wire invariants (INSERT / COPY / END token contracts), runtime invariants per code path, the failure-mode -> regression-test table, and fuzz target rationale. - New complementary fuzz target fuzz/fuzz_targets/zlib_token_decode.rs drives CountingZlibDecoder through arbitrary byte sequences under streaming read semantics. Asserts panic-freedom, monotonic byte-counter, and 100x expansion ceiling. Uses only existing crate APIs. - Two new unit tests in crates/compress/src/zlib/tests.rs pin the malformed-INSERT and COPY-past-EOF panic-freedom guarantees at the streaming decoder layer (malformed stored-block NLEN check, post-EOF Ok(0) tail reads). - Wires zlib_token_decode into the nightly fuzz-coverage matrix workflow and the FCV-20.c coverage tracking table.
2 tasks
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
Records the wire-byte and runtime invariants that govern the delta-transfer codec stack: the upstream-compatible zlib token decoder, the BufferedMap basis-window mapper, and the streaming raw-deflate primitives in the compress crate. Closes the documentation gap left open by the UTS-18 series (BufferedMap fail-loud bounds, window_len clamp, never-shrink) and PR #5535 (URV-1 zlib obuf overflow on matched-block inserts). - New design doc at docs/design/zlib-codec-invariants.md catalogues wire invariants (INSERT / COPY / END token contracts), runtime invariants per code path, the failure-mode -> regression-test table, and fuzz target rationale. - New complementary fuzz target fuzz/fuzz_targets/zlib_token_decode.rs drives CountingZlibDecoder through arbitrary byte sequences under streaming read semantics. Asserts panic-freedom, monotonic byte-counter, and 100x expansion ceiling. Uses only existing crate APIs. - Two new unit tests in crates/compress/src/zlib/tests.rs pin the malformed-INSERT and COPY-past-EOF panic-freedom guarantees at the streaming decoder layer (malformed stored-block NLEN check, post-EOF Ok(0) tail reads). - Wires zlib_token_decode into the nightly fuzz-coverage matrix workflow and the FCV-20.c coverage tracking table.
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
ZlibTokenEncoder::see_token, instead of issuing a singlecompress()call that could drop the unconsumed tail when the output buffer fills under pending sync-flush pressure.AVAIL_OUT_SIZE(0xFFFF) + 16) so a maximum-size stored block plus theZ_SYNC_FLUSHtrailer always fits in a single pass.Rationale
Mirrors upstream rsync issue #951 against
token.c:send_deflated_token(). The upstreamobufis sized forAVAIL_OUT_SIZE(CHUNK_SIZE) = 32 816bytes, but the matched-block insert path can deflate up to0xFFFFbytes per call while still carrying pending output from a precedingZ_SYNC_FLUSH. The corresponding flate2-based path inherited the same under-sized reserve and additionally never looped on partial consumption, so the encoder's dictionary silently diverged from the decoder's whenever a basis match landed at the obuf boundary.The protocol < 31 data-duplicating bug is preserved so wire behaviour stays bit-compatible with legacy peers.
Test plan
see_token_drains_64kib_insert_with_pending_flush_outputandsee_token_handles_exact_max_stored_block.