Debian Codegraph @

testsuite/append-shortsum_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """Regression: a short transfer checksum must not over-state the block s2length.
3
4 A full-checksum (--append-verify redo) pass computes the strong block sum length
5 (s2length). The generator used to cap it at SUM_LENGTH (16), the legacy MD4/MD5
6 digest size, regardless of the negotiated algorithm. Since the sum2 array holds
7 xfer_sum_len-byte elements and the sender rejects an s2length larger than
8 xfer_sum_len, a sub-16-byte transfer checksum -- xxh64 (8 bytes), which is what
9 rsync negotiates when the build's libxxhash lacks xxh128/xxh3 (e.g. Ubuntu
10 20.04) -- made the sender die with "Invalid checksum length 16 [sender]"
11 (protocol incompatibility, code 2).
12
13 Forcing --checksum-choice=xxh64 reproduces it on any build that has xxhash, so
14 this guards the fix without needing an old-libxxhash host. Skipped where xxh64
15 is unavailable (a build without xxhash).
16 """
17
18 import json
19
20 from rsyncfns import (
21 FROMDIR, TODIR, assert_same, make_data_file, rmtree, run_rsync,
22 test_skipped,
23 )
24
25 vv = json.loads(run_rsync('-VV', check=True, capture_output=True).stdout)
26 if 'xxh64' not in vv.get('checksum_list', []):
27 test_skipped("xxh64 not in this build's checksum list (no xxhash)")
28
29 src, dst = FROMDIR, TODIR
30 rmtree(src)
31 rmtree(dst)
32 src.mkdir(parents=True)
33 dst.mkdir(parents=True)
34
35 # Source longer than the destination so --append has bytes to add; the dest is a
36 # *corrupted* prefix so --append-verify's whole-file check fails and the file is
37 # redone with a full checksum -- the csum_length == SUM_LENGTH path that emitted
38 # the over-long s2length.
39 make_data_file(src / 'f', 40000)
40 full = (src / 'f').read_bytes()
41 prefix = bytearray(full[:20000])
42 prefix[0:64] = b'\x00' * 64
43 (dst / 'f').write_bytes(bytes(prefix))
44
45 # --no-whole-file forces the delta/checksum path regardless of local-vs-remote.
46 # run_rsync(check=True) fails the test on the non-zero exit the bug produced.
47 run_rsync('-a', '--append-verify', '--checksum-choice=xxh64', '--no-whole-file',
48 f'{src}/', f'{dst}/')
49 assert_same(dst / 'f', src / 'f', label='append-verify xxh64 redo')
50
51 print("append-shortsum: --append-verify with an 8-byte (xxh64) checksum no "
52 "longer overflows the block s2length")