1 This patch adds a safety check to prevent an xxhash 0.7 lib from being used to
2 perform xxh3 checksums.
4 To use this patch, run these commands for a successful build:
6 patch -p1 <patches/xxh3-safety-check.diff
9 based-on: c3b553a93f7090bcbb89c08405f1a5f1c175c864
10 diff --git a/checksum.c b/checksum.c
13 @@ -62,6 +62,8 @@ struct name_num_obj valid_checksums = {
14 int xfersum_type = 0; /* used for the file transfer checksums */
15 int checksum_type = 0; /* used for the pre-transfer (--checksum) checksums */
17 +static int initialized_choices = 0;
19 int parse_csum_name(const char *name, int len)
21 struct name_num_item *nni;
22 @@ -79,6 +81,9 @@ int parse_csum_name(const char *name, int len)
23 return CSUM_MD4_ARCHAIC;
26 + if (!initialized_choices)
27 + init_checksum_choices();
29 nni = get_nni_by_name(&valid_checksums, name, len);
32 @@ -623,3 +628,31 @@ int sum_end(char *sum)
34 return csum_len_for_type(cursum_type, 0);
37 +void init_checksum_choices()
42 + for (j = 0; j < (int)sizeof buf; j++) {
43 + buf[j] = ' ' + (j % 96);
45 + sum_init(CSUM_XXH3_64, 0);
46 + sum_update(buf, 32816);
47 + sum_update(buf, 31152);
48 + sum_update(buf, 32474);
49 + sum_update(buf, 9322);
50 + if (XXH3_64bits_digest(xxh3_state) != 0xadbcf16d4678d1de) {
52 + struct name_num_item *nni = valid_checksums.list;
53 + for (t = f = 0; nni[f].name; f++) {
54 + if (nni[f].num == CSUM_XXH3_64 || nni[f].num == CSUM_XXH3_128)
62 + initialized_choices = 1;
64 diff --git a/compat.c b/compat.c
67 @@ -523,6 +523,8 @@ static void negotiate_the_strings(int f_in, int f_out)
69 /* We send all the negotiation strings before we start to read them to help avoid a slow startup. */
71 + init_checksum_choices();
74 send_negotiate_str(f_out, &valid_checksums, NSTR_CHECKSUM);
76 diff --git a/usage.c b/usage.c
79 @@ -190,6 +190,8 @@ void print_rsync_version(enum logcode f)
83 + init_checksum_choices();
85 rprintf(f, "Checksum list:\n");
86 get_default_nno_list(&valid_checksums, tmpbuf, sizeof tmpbuf, '(');
87 rprintf(f, " %s\n", tmpbuf);