diff-delta: fix encoding size that would not fit in "unsigned int"
The current delta code produces incorrect pack objects for files > 4GB, because the size is copied from size_t field to "unsigned int" variables during the encoding process. Signed-off-by: Martin Koegler <martin.koegler@chello.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Martin Koegler committed
Aug 10, 2017 at 09:01 UTC
3f0a67a1f68d79f102ac11a8b6e7a72dc86be613
1 file changed
+13
-11
diff-delta.c
+13
-11
@@ -319,7 +319,9 @@ create_delta(const struct delta_index *index,
319
const void *trg_buf, unsigned long trg_size,
320
unsigned long *delta_size, unsigned long max_size)
321
{
322
- unsigned int i, outpos, outsize, moff, msize, val;
322
+ unsigned int i, val;
323
+ off_t outpos, moff;
324
+ size_t l, outsize, msize;
325
int inscnt;
326
const unsigned char *ref_data, *ref_top, *data, *top;
327
unsigned char *out;
@@ -336,20 +338,20 @@ create_delta(const struct delta_index *index,
338
return NULL;
339
340
/* store reference buffer size */
339
- i = index->src_size;
340
- while (i >= 0x80) {
341
- out[outpos++] = i | 0x80;
342
- i >>= 7;
341
+ l = index->src_size;
342
+ while (l >= 0x80) {
343
+ out[outpos++] = l | 0x80;
344
+ l >>= 7;
345
}
344
- out[outpos++] = i;
346
+ out[outpos++] = l;
347
348
/* store target buffer size */
347
- i = trg_size;
348
- while (i >= 0x80) {
349
- out[outpos++] = i | 0x80;
350
- i >>= 7;
349
+ l = trg_size;
350
+ while (l >= 0x80) {
351
+ out[outpos++] = l | 0x80;
352
+ l >>= 7;
353
}
352
- out[outpos++] = i;
354
+ out[outpos++] = l;
355
356
ref_data = index->src_buf;
357
ref_top = ref_data + index->src_size;