Repository navigation
fix(checksums): rolling checksum sign-extends bytes to match upstream schar - #3560
Merged
Merged
Conversation
Upstream rsync's checksum.c:get_checksum1() casts bytes via
`schar *buf = (schar *)buf1`, treating each byte as signed (-128..127).
oc-rsync was treating bytes as unsigned (0..255), causing per-byte
divergence for any byte >= 0x80. This produced wrong rolling checksums
on any binary basis file with high bytes, breaking delta-stats interop
against upstream rsync.
Fix all rolling-checksum code paths to sign-extend before accumulation:
- Scalar 4-byte unrolled loop (sign_extend_byte helper)
- update_byte fast path
- roll() outgoing/incoming bytes
- roll_many() outgoing/incoming bytes
- AVX2: _mm256_cvtepi8_epi16 direct widening + _mm256_madd_epi16
- SSE2: _mm_cmplt_epi8 sign-mask + _mm_unpacklo/hi_epi8 + _mm_madd_epi16
- NEON: vreinterpretq_s8_u8 + vmovl_s8 + vaddlvq_s16 (widening reduction
avoids vaddvq_s16 i16 overflow)
Property-test reference (rolling_simd_parity.rs) and golden values
(tests.rs, rsync_rolling_compat.rs) updated to match upstream signed
semantics:
- all_ff golden: 0xff78_fff0 (was 0x8778_0ff0); 0xFF == -1 signed,
s1 = -16 = 0xfff0, s2 = -136 = 0xff78
- block_length_700 golden: 0x01ea_fe96 (was 0xe2ea_5c96)
- block_length_4096 golden: 0x2000_f800 (unchanged; bytes <0x80 only)
Refs: project_delta_stats_wire_evidence.md
Upstream rsync's `checksum.c:get_checksum1()` uses `schar *buf = (schar *)buf1`, sign-extending bytes to [-128,127]. For bytes >= 0x80 the contribution to s1/s2 is (byte - 256), not byte. The single-byte expectation was using the old unsigned cast and failed for byte 128 (expected 8388736, got 4286644096).
2 tasks
oferchen
added a commit
that referenced
this pull request
May 5, 2026
… schar (#3560) * fix(checksums): sign-extend bytes in rolling checksum to match upstream Upstream rsync's checksum.c:get_checksum1() casts bytes via `schar *buf = (schar *)buf1`, treating each byte as signed (-128..127). oc-rsync was treating bytes as unsigned (0..255), causing per-byte divergence for any byte >= 0x80. This produced wrong rolling checksums on any binary basis file with high bytes, breaking delta-stats interop against upstream rsync. Fix all rolling-checksum code paths to sign-extend before accumulation: - Scalar 4-byte unrolled loop (sign_extend_byte helper) - update_byte fast path - roll() outgoing/incoming bytes - roll_many() outgoing/incoming bytes - AVX2: _mm256_cvtepi8_epi16 direct widening + _mm256_madd_epi16 - SSE2: _mm_cmplt_epi8 sign-mask + _mm_unpacklo/hi_epi8 + _mm_madd_epi16 - NEON: vreinterpretq_s8_u8 + vmovl_s8 + vaddlvq_s16 (widening reduction avoids vaddvq_s16 i16 overflow) Property-test reference (rolling_simd_parity.rs) and golden values (tests.rs, rsync_rolling_compat.rs) updated to match upstream signed semantics: - all_ff golden: 0xff78_fff0 (was 0x8778_0ff0); 0xFF == -1 signed, s1 = -16 = 0xfff0, s2 = -136 = 0xff78 - block_length_700 golden: 0x01ea_fe96 (was 0xe2ea_5c96) - block_length_4096 golden: 0x2000_f800 (unchanged; bytes <0x80 only) Refs: project_delta_stats_wire_evidence.md * style(checksums): cargo fmt import ordering in rolling x86.rs * test(checksums): update single_byte_checksum for signed-byte semantics Upstream rsync's `checksum.c:get_checksum1()` uses `schar *buf = (schar *)buf1`, sign-extending bytes to [-128,127]. For bytes >= 0x80 the contribution to s1/s2 is (byte - 256), not byte. The single-byte expectation was using the old unsigned cast and failed for byte 128 (expected 8388736, got 4286644096).
This was referenced May 5, 2026
oferchen
added a commit
that referenced
this pull request
May 5, 2026
Construct adversarial pairs of 700-byte blocks that share an identical rolling Adler digest (signed-byte interpretation) but have different content. Verify that DeltaSignatureIndex::find_match_bytes rejects the colliding window via the strong-checksum gate. This is the safety property that future probabilistic prefilters (e.g. a bithash) will depend on: even if the prefilter admits the rolling key, the strong-checksum stage must catch the mismatch. Includes a high-byte (>= 0x80) variant that exercises the signed-schar path from upstream checksum.c:285, providing additional regression coverage for the sign-extension fix in PR #3560. Construction: swap last 4 bytes [a, b, c, d] -> [d, c, b, a] when 3*(a-d) == c-b. Two solutions used: low-byte [0x01, 0x00, 0x03, 0x00] and high-byte [0x80, 0x86, 0x80, 0x82].
oferchen
added a commit
that referenced
this pull request
May 5, 2026
…3640) Construct adversarial pairs of 700-byte blocks that share an identical rolling Adler digest (signed-byte interpretation) but have different content. Verify that DeltaSignatureIndex::find_match_bytes rejects the colliding window via the strong-checksum gate. This is the safety property that future probabilistic prefilters (e.g. a bithash) will depend on: even if the prefilter admits the rolling key, the strong-checksum stage must catch the mismatch. Includes a high-byte (>= 0x80) variant that exercises the signed-schar path from upstream checksum.c:285, providing additional regression coverage for the sign-extension fix in PR #3560. Construction: swap last 4 bytes [a, b, c, d] -> [d, c, b, a] when 3*(a-d) == c-b. Two solutions used: low-byte [0x01, 0x00, 0x03, 0x00] and high-byte [0x80, 0x86, 0x80, 0x82].
6 tasks
oferchen
added a commit
that referenced
this pull request
May 5, 2026
#3723) Add design note for the canonical zsync-style insertion adversary at docs/design/zsync-shifted-insertion-test.md, pinning the public-API guard for the four pipeline optimizations enumerated in docs/design/zsync-inspired-matching.md (#2053). Documents the fixture parameters, expected match output for aligned vs unaligned regimes, the upstream rsync --stats comparison oracle, CI integration gated by SIMD parity (#2077), and the failure modes (signed-byte regression #2076 class, off-by-one in seek, bithash false negative #2061-#2063 class, want_i hint off-by-one, rolling-window reset bugs, strong-checksum truncation drift, ring-buffer wrap bugs). Cites the existing fixture at crates/match/tests/shifted_insertion_fixture.rs, the sibling rsum-collision fixture from #2078, and the rolling sign-extension fix from PR #3560 (commit 723a0a0).
2 tasks
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…3640) Construct adversarial pairs of 700-byte blocks that share an identical rolling Adler digest (signed-byte interpretation) but have different content. Verify that DeltaSignatureIndex::find_match_bytes rejects the colliding window via the strong-checksum gate. This is the safety property that future probabilistic prefilters (e.g. a bithash) will depend on: even if the prefilter admits the rolling key, the strong-checksum stage must catch the mismatch. Includes a high-byte (>= 0x80) variant that exercises the signed-schar path from upstream checksum.c:285, providing additional regression coverage for the sign-extension fix in PR #3560. Construction: swap last 4 bytes [a, b, c, d] -> [d, c, b, a] when 3*(a-d) == c-b. Two solutions used: low-byte [0x01, 0x00, 0x03, 0x00] and high-byte [0x80, 0x86, 0x80, 0x82].
oferchen
added a commit
that referenced
this pull request
May 18, 2026
#3723) Add design note for the canonical zsync-style insertion adversary at docs/design/zsync-shifted-insertion-test.md, pinning the public-API guard for the four pipeline optimizations enumerated in docs/design/zsync-inspired-matching.md (#2053). Documents the fixture parameters, expected match output for aligned vs unaligned regimes, the upstream rsync --stats comparison oracle, CI integration gated by SIMD parity (#2077), and the failure modes (signed-byte regression #2076 class, off-by-one in seek, bithash false negative #2061-#2063 class, want_i hint off-by-one, rolling-window reset bugs, strong-checksum truncation drift, ring-buffer wrap bugs). Cites the existing fixture at crates/match/tests/shifted_insertion_fixture.rs, the sibling rsum-collision fixture from #2078, and the rolling sign-extension fix from PR #3560 (commit 723a0a0).
3 of 5 tasks
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…3640) Construct adversarial pairs of 700-byte blocks that share an identical rolling Adler digest (signed-byte interpretation) but have different content. Verify that DeltaSignatureIndex::find_match_bytes rejects the colliding window via the strong-checksum gate. This is the safety property that future probabilistic prefilters (e.g. a bithash) will depend on: even if the prefilter admits the rolling key, the strong-checksum stage must catch the mismatch. Includes a high-byte (>= 0x80) variant that exercises the signed-schar path from upstream checksum.c:285, providing additional regression coverage for the sign-extension fix in PR #3560. Construction: swap last 4 bytes [a, b, c, d] -> [d, c, b, a] when 3*(a-d) == c-b. Two solutions used: low-byte [0x01, 0x00, 0x03, 0x00] and high-byte [0x80, 0x86, 0x80, 0x82].
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
#3723) Add design note for the canonical zsync-style insertion adversary at docs/design/zsync-shifted-insertion-test.md, pinning the public-API guard for the four pipeline optimizations enumerated in docs/design/zsync-inspired-matching.md (#2053). Documents the fixture parameters, expected match output for aligned vs unaligned regimes, the upstream rsync --stats comparison oracle, CI integration gated by SIMD parity (#2077), and the failure modes (signed-byte regression #2076 class, off-by-one in seek, bithash false negative #2061-#2063 class, want_i hint off-by-one, rolling-window reset bugs, strong-checksum truncation drift, ring-buffer wrap bugs). Cites the existing fixture at crates/match/tests/shifted_insertion_fixture.rs, the sibling rsum-collision fixture from #2078, and the rolling sign-extension fix from PR #3560 (commit 723a0a0).
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
Upstream rsync's
checksum.c:get_checksum1()casts bytes viaschar *buf = (schar *)buf1, treating each byte as signed (-128..127). oc-rsync was treating bytes as unsigned (0..255), causing per-byte divergence on any byte >= 0x80. This produced wrong rolling checksums on any binary basis file with high bytes, breaking thestandalone:delta-statsinterop test against upstream rsync.Root-caused from pcap evidence captured against a basis file containing high bytes; oc-rsync's rolling sums diverged from upstream's exactly where bytes >= 0x80 first appeared.
Changes
All rolling-checksum code paths now sign-extend bytes before accumulation:
sign_extend_bytehelper)update_bytefast pathroll()outgoing/incoming bytesroll_many()outgoing/incoming bytes_mm256_cvtepi8_epi16direct widening +_mm256_madd_epi16_mm_cmplt_epi8sign-mask +_mm_unpacklo/hi_epi8+_mm_madd_epi16vreinterpretq_s8_u8+vmovl_s8+vaddlvq_s16widening reduction (avoidsvaddvq_s16i16 overflow risk)Property-test reference (
rolling_simd_parity.rs) and goldens (tests.rs,rsync_rolling_compat.rs) updated to match upstream signed semantics:0x8778_0ff00xff78_fff00xe2ea_5c960x01ea_fe960x2000_f8000x2000_f800Test plan
standalone:delta-statsshould now passrolling_simd_parity.rsconfirm SIMD vs scalar parity over the full byte range