Skip to content

Commit 0902b52

Browse files
committed
Some checksum buffer fixes.
- Put sum2_array into sum_struct to hold an array of sum2 checksums that are each xfer_sum_len bytes. - Remove sum2 buf from sum_buf. - Add macro sum2_at() to access each sum2 array element. - Throw an error if a sums header has an s2length larger than xfer_sum_len.
1 parent 9615a24 commit 0902b52

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

io.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ extern int read_batch;
5555
extern int compat_flags;
5656
extern int protect_args;
5757
extern int checksum_seed;
58+
extern int xfer_sum_len;
5859
extern int daemon_connection;
5960
extern int protocol_version;
6061
extern int remove_source_files;
@@ -1977,7 +1978,7 @@ void read_sum_head(int f, struct sum_struct *sum)
19771978
exit_cleanup(RERR_PROTOCOL);
19781979
}
19791980
sum->s2length = protocol_version < 27 ? csum_length : (int)read_int(f);
1980-
if (sum->s2length < 0 || sum->s2length > MAX_DIGEST_LEN) {
1981+
if (sum->s2length < 0 || sum->s2length > xfer_sum_len) {
19811982
rprintf(FERROR, "Invalid checksum length %d [%s]\n",
19821983
sum->s2length, who_am_i());
19831984
exit_cleanup(RERR_PROTOCOL);

match.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static void hash_search(int f,struct sum_struct *s,
232232
done_csum2 = 1;
233233
}
234234

235-
if (memcmp(sum2,s->sums[i].sum2,s->s2length) != 0) {
235+
if (memcmp(sum2, sum2_at(s, i), s->s2length) != 0) {
236236
false_alarms++;
237237
continue;
238238
}
@@ -252,7 +252,7 @@ static void hash_search(int f,struct sum_struct *s,
252252
if (i != aligned_i) {
253253
if (sum != s->sums[aligned_i].sum1
254254
|| l != s->sums[aligned_i].len
255-
|| memcmp(sum2, s->sums[aligned_i].sum2, s->s2length) != 0)
255+
|| memcmp(sum2, sum2_at(s, aligned_i), s->s2length) != 0)
256256
goto check_want_i;
257257
i = aligned_i;
258258
}
@@ -271,7 +271,7 @@ static void hash_search(int f,struct sum_struct *s,
271271
if (sum != s->sums[i].sum1)
272272
goto check_want_i;
273273
get_checksum2((char *)map, l, sum2);
274-
if (memcmp(sum2, s->sums[i].sum2, s->s2length) != 0)
274+
if (memcmp(sum2, sum2_at(s, i), s->s2length) != 0)
275275
goto check_want_i;
276276
/* OK, we have a re-alignment match. Bump the offset
277277
* forward to the new match point. */
@@ -290,7 +290,7 @@ static void hash_search(int f,struct sum_struct *s,
290290
&& (!updating_basis_file || s->sums[want_i].offset >= offset
291291
|| s->sums[want_i].flags & SUMFLG_SAME_OFFSET)
292292
&& sum == s->sums[want_i].sum1
293-
&& memcmp(sum2, s->sums[want_i].sum2, s->s2length) == 0) {
293+
&& memcmp(sum2, sum2_at(s, want_i), s->s2length) == 0) {
294294
/* we've found an adjacent match - the RLL coder
295295
* will be happy */
296296
i = want_i;

rsync.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,10 @@ int read_ndx_and_attrs(int f_in, int f_out, int *iflag_ptr, uchar *type_ptr, cha
437437
*/
438438
void free_sums(struct sum_struct *s)
439439
{
440-
if (s->sums) free(s->sums);
440+
if (s->sums) {
441+
free(s->sums);
442+
free(s->sum2_array);
443+
}
441444
free(s);
442445
}
443446

rsync.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -958,12 +958,12 @@ struct sum_buf {
958958
uint32 sum1; /**< simple checksum */
959959
int32 chain; /**< next hash-table collision */
960960
short flags; /**< flag bits */
961-
char sum2[SUM_LENGTH]; /**< checksum */
962961
};
963962

964963
struct sum_struct {
965964
OFF_T flength; /**< total file length */
966965
struct sum_buf *sums; /**< points to info for each chunk */
966+
char *sum2_array; /**< checksums of length xfer_sum_len */
967967
int32 count; /**< how many chunks */
968968
int32 blength; /**< block_length */
969969
int32 remainder; /**< flength % block_length */
@@ -982,6 +982,8 @@ struct map_struct {
982982
int status; /* first errno from read errors */
983983
};
984984

985+
#define sum2_at(s, i) ((s)->sum2_array + ((OFF_T)(i) * xfer_sum_len))
986+
985987
#define NAME_IS_FILE (0) /* filter name as a file */
986988
#define NAME_IS_DIR (1<<0) /* filter name as a dir */
987989
#define NAME_IS_XATTR (1<<2) /* filter name as an xattr */

sender.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern int log_before_transfer;
3131
extern int stdout_format_has_i;
3232
extern int logfile_format_has_i;
3333
extern int want_xattr_optim;
34+
extern int xfer_sum_len;
3435
extern int csum_length;
3536
extern int append_mode;
3637
extern int copy_links;
@@ -94,10 +95,11 @@ static struct sum_struct *receive_sums(int f)
9495
return(s);
9596

9697
s->sums = new_array(struct sum_buf, s->count);
98+
s->sum2_array = new_array(char, s->count * xfer_sum_len);
9799

98100
for (i = 0; i < s->count; i++) {
99101
s->sums[i].sum1 = read_int(f);
100-
read_buf(f, s->sums[i].sum2, s->s2length);
102+
read_buf(f, sum2_at(s, i), s->s2length);
101103

102104
s->sums[i].offset = offset;
103105
s->sums[i].flags = 0;

0 commit comments

Comments
 (0)