Skip to content

test(compress): wire-byte regression for zlib_codec at protocol < 31 (RP28.i) - #4870

Merged
oferchen merged 6 commits into
masterfrom
test/rp28-i-zlib-codec-proto-lt-31
May 24, 2026
Merged

oferchen merged 6 commits into
masterfrom
test/rp28-i-zlib-codec-proto-lt-31

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Adds crates/protocol/tests/zlib_codec_proto_lt_31.rs, a wire-byte
    regression test that pins the protocol-version gate in
    ZlibTokenEncoder::see_token.
  • Exercises a fixture where see_token is fed 0x10001 bytes (one byte
    past the 0xFFFF chunk boundary) so the inner chunk-feeding loop
    iterates twice. At protocol < 31 the offset cursor never advances
    and the same window is re-inserted into the deflate dictionary, which
    is the upstream data-duplicating bug preserved for pre-31 wire
    compatibility.
  • A short trailing literal is then compressed; the resulting
    DEFLATED_DATA payload reflects the protocol-conditioned dictionary
    state and therefore differs between the two branches.

Assertions

Property Coverage
END_FLAG terminator both protocols
At least one DEFLATED_DATA block both protocols
Protocol 30 wire bytes != protocol 31 divergence on the >= 31 gate
Protocol 31 wire bytes == protocol 32 shared modern branch
Protocols 28, 29, 30 each diverge from 32 full pre-31 family

Upstream reference

The gate is implemented in upstream token.c:send_deflated_token()
lines 463-484 of target/interop/upstream-src/rsync-3.4.1/token.c:

} else if (token != -2 && do_compression == CPRES_ZLIB) {
    do {
        int32 n1 = toklen > 0xffff ? 0xffff : toklen;
        toklen -= n1;
        tx_strm.next_in = (Bytef *)map_ptr(buf, offset, n1);
        tx_strm.avail_in = n1;
        if (protocol_version >= 31) /* Newer protocols avoid a data-duplicating bug */
            offset += n1;
        ...
        r = deflate(&tx_strm, Z_INSERT_ONLY);
        ...
    } while (toklen > 0);
}

The mirror lives in crates/protocol/src/wire/compressed_token/zlib_codec.rs
inside ZlibTokenEncoder::see_token (the if self.protocol_version >= 31
branch around line 131).

Backend portability

Exact bytes inside the DEFLATED_DATA payload depend on the active
flate2 backend (default miniz_oxide, plus zlib-ng and zlib-rs
feature builds). The test pins relative wire-byte properties (framing
invariants plus inter-protocol inequality) rather than a backend-specific
byte sequence, so all three backends pass.

Test plan

  • CI: protocol-crate nextest passes on Linux/macOS/Windows with the
    default zlib-ng backend.
  • CI: musl build (which uses miniz_oxide via default-features = false)
    also passes the same assertions.

@github-actions github-actions Bot added the test label May 24, 2026
@oferchen
oferchen force-pushed the test/rp28-i-zlib-codec-proto-lt-31 branch 2 times, most recently from 6847f69 to 3299c22 Compare May 24, 2026 16:26
@oferchen
oferchen force-pushed the test/rp28-i-zlib-codec-proto-lt-31 branch from 3299c22 to f4a8e62 Compare May 24, 2026 16:35
@oferchen
oferchen force-pushed the test/rp28-i-zlib-codec-proto-lt-31 branch from f4a8e62 to b54db4e Compare May 24, 2026 16:49
oferchen added 6 commits May 24, 2026 21:26
…(RP28.i)

Pins the wire-byte divergence between protocol 30 and protocol 31 in
ZlibTokenEncoder::see_token when the input straddles the 0xFFFF chunk
boundary. Protocol < 31 leaves the offset cursor un-advanced and
re-inserts the same window into the deflate dictionary each iteration,
matching the upstream data-duplicating bug behaviour kept for
compatibility with pre-31 peers (token.c:473).

The test asserts:
- both protocols terminate with END_FLAG and emit at least one
  DEFLATED_DATA block;
- protocol 30 output differs from protocol 31 for the same fixture;
- protocol 31 and protocol 32 produce byte-identical output (shared
  >= 31 branch);
- every supported pre-31 version (28, 29, 30) diverges from the
  modern baseline.

Backend-portable: compares relative byte sequences rather than pinning
backend-specific compressed payload bytes.
Line 35 starts with ">= 31" which markdown parses as a blockquote
marker; clippy doc_lazy_continuation then flags lines 36-38 for
missing markers. Rewrap so no continuation line begins with ">".
…e bytes

The previous fixture (0x10001-byte see_buf + ASCII-only literal) gave a
2-byte tail divergence between the protocol-31 and protocol-30
dictionaries, which is too short for deflate's >= 3-byte minimum-match
to encode as different back-references. Both protocol families compressed
to byte-identical output, so the assertion never tripped even though the
protocol-version gate at zlib_codec.rs:131 was the intended subject.

Bump see_buf size to 0xFFFF + 4 to produce a 4-byte tail divergence,
and prefix the literal with [0xFF, 0x00, 0x01, 0x02] so deflate finds
the sequence at the protocol-31 dictionary tail at a small
back-reference distance versus the interior of the protocol-30
dictionary at a much larger distance. The encoded distances and lengths
diverge, so the wire bytes diverge.

Verified end-to-end: tests pass with the protocol-version gate in
place, and flipping the gate to `if false` reproduces the original
divergence failures (confirming the test catches gate removal).
@oferchen
oferchen force-pushed the test/rp28-i-zlib-codec-proto-lt-31 branch from 9241548 to 4ceb7f0 Compare May 24, 2026 18:26
@oferchen
oferchen merged commit 1073dd2 into master May 24, 2026
60 of 61 checks passed
@oferchen
oferchen deleted the test/rp28-i-zlib-codec-proto-lt-31 branch May 28, 2026 03:37
oferchen added a commit that referenced this pull request Aug 24, 2026
…(RP28.i) (#4870)

* test(compress): wire-byte regression for zlib_codec at protocol < 31 (RP28.i)

Pins the wire-byte divergence between protocol 30 and protocol 31 in
ZlibTokenEncoder::see_token when the input straddles the 0xFFFF chunk
boundary. Protocol < 31 leaves the offset cursor un-advanced and
re-inserts the same window into the deflate dictionary each iteration,
matching the upstream data-duplicating bug behaviour kept for
compatibility with pre-31 peers (token.c:473).

The test asserts:
- both protocols terminate with END_FLAG and emit at least one
  DEFLATED_DATA block;
- protocol 30 output differs from protocol 31 for the same fixture;
- protocol 31 and protocol 32 produce byte-identical output (shared
  >= 31 branch);
- every supported pre-31 version (28, 29, 30) diverges from the
  modern baseline.

Backend-portable: compares relative byte sequences rather than pinning
backend-specific compressed payload bytes.

* style(compress): apply rustfmt to zlib_codec_proto_lt_31.rs

* ci(compress): retrigger fmt+clippy on zlib_codec_proto_lt_31

* ci(compress): retrigger CI on RP28.i after master fmt fixup #4891

* fix(tests): rewrap zlib_codec doc to avoid blockquote misparse

Line 35 starts with ">= 31" which markdown parses as a blockquote
marker; clippy doc_lazy_continuation then flags lines 36-38 for
missing markers. Rewrap so no continuation line begins with ">".

* fix(tests): rewrite RP28.i fixture so see_token gate manifests in wire bytes

The previous fixture (0x10001-byte see_buf + ASCII-only literal) gave a
2-byte tail divergence between the protocol-31 and protocol-30
dictionaries, which is too short for deflate's >= 3-byte minimum-match
to encode as different back-references. Both protocol families compressed
to byte-identical output, so the assertion never tripped even though the
protocol-version gate at zlib_codec.rs:131 was the intended subject.

Bump see_buf size to 0xFFFF + 4 to produce a 4-byte tail divergence,
and prefix the literal with [0xFF, 0x00, 0x01, 0x02] so deflate finds
the sequence at the protocol-31 dictionary tail at a small
back-reference distance versus the interior of the protocol-30
dictionary at a much larger distance. The encoded distances and lengths
diverge, so the wire bytes diverge.

Verified end-to-end: tests pass with the protocol-version gate in
place, and flipping the gate to `if false` reproduces the original
divergence failures (confirming the test catches gate removal).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant