The patches for 3.2.4pre2.
[rsync-patches.git] / xxh3-safety-check.diff
1 This patch adds a safety check to prevent an xxhash 0.7 lib from being used to
2 perform xxh3 checksums.
3
4 To use this patch, run these commands for a successful build:
5
6     patch -p1 <patches/xxh3-safety-check.diff
7     make
8
9 based-on: c3b553a93f7090bcbb89c08405f1a5f1c175c864
10 diff --git a/checksum.c b/checksum.c
11 --- a/checksum.c
12 +++ 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 */
16  
17 +static int initialized_choices = 0;
18 +
19  int parse_csum_name(const char *name, int len)
20  {
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;
24         }
25  
26 +       if (!initialized_choices)
27 +               init_checksum_choices();
28 +
29         nni = get_nni_by_name(&valid_checksums, name, len);
30  
31         if (!nni) {
32 @@ -623,3 +628,31 @@ int sum_end(char *sum)
33  
34         return csum_len_for_type(cursum_type, 0);
35  }
36 +
37 +void init_checksum_choices()
38 +{
39 +#ifdef SUPPORT_XXH3
40 +       char buf[32816];
41 +       int j;
42 +       for (j = 0; j < (int)sizeof buf; j++) {
43 +               buf[j] = ' ' + (j % 96);
44 +       }
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) {
51 +               int t, f;
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)
55 +                               continue;
56 +                       if (t != f)
57 +                               nni[t++] = nni[f];
58 +               }
59 +               nni[t].name = NULL;
60 +       }
61 +#endif
62 +       initialized_choices = 1;
63 +}
64 diff --git a/compat.c b/compat.c
65 --- a/compat.c
66 +++ b/compat.c
67 @@ -523,6 +523,8 @@ static void negotiate_the_strings(int f_in, int f_out)
68  {
69         /* We send all the negotiation strings before we start to read them to help avoid a slow startup. */
70  
71 +       init_checksum_choices();
72 +
73         if (!checksum_choice)
74                 send_negotiate_str(f_out, &valid_checksums, NSTR_CHECKSUM);
75  
76 diff --git a/usage.c b/usage.c
77 --- a/usage.c
78 +++ b/usage.c
79 @@ -190,6 +190,8 @@ void print_rsync_version(enum logcode f)
80  
81         print_info_flags(f);
82  
83 +       init_checksum_choices();
84 +
85         rprintf(f, "Checksum list:\n");
86         get_default_nno_list(&valid_checksums, tmpbuf, sizeof tmpbuf, '(');
87         rprintf(f, "    %s\n", tmpbuf);