refs: convert read_raw_ref backends to struct object_id
[gitweb.git] / diff-delta.c
index 464ac3ffc0a45e95637e2cecdf97b3d39e5c7933..e49643353bf56807b3d4ac4011784b5d8dd6f7a4 100644 (file)
@@ -146,9 +146,16 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
        /* Determine index hash size.  Note that indexing skips the
           first byte to allow for optimizing the Rabin's polynomial
           initialization in create_delta(). */
-       entries = (bufsize - 1)  / RABIN_WINDOW;
+       entries = (bufsize - 1) / RABIN_WINDOW;
+       if (bufsize >= 0xffffffffUL) {
+               /*
+                * Current delta format can't encode offsets into
+                * reference buffer with more than 32 bits.
+                */
+               entries = 0xfffffffeU / RABIN_WINDOW;
+       }
        hsize = entries / 4;
-       for (i = 4; (1u << i) < hsize && i < 31; i++);
+       for (i = 4; (1u << i) < hsize; i++);
        hsize = 1 << i;
        hmask = hsize - 1;
 
@@ -312,7 +319,9 @@ create_delta(const struct delta_index *index,
             const void *trg_buf, unsigned long trg_size,
             unsigned long *delta_size, unsigned long max_size)
 {
-       unsigned int i, outpos, outsize, moff, msize, val;
+       unsigned int i, val;
+       off_t outpos, moff;
+       size_t l, outsize, msize;
        int inscnt;
        const unsigned char *ref_data, *ref_top, *data, *top;
        unsigned char *out;
@@ -329,20 +338,20 @@ create_delta(const struct delta_index *index,
                return NULL;
 
        /* store reference buffer size */
-       i = index->src_size;
-       while (i >= 0x80) {
-               out[outpos++] = i | 0x80;
-               i >>= 7;
+       l = index->src_size;
+       while (l >= 0x80) {
+               out[outpos++] = l | 0x80;
+               l >>= 7;
        }
-       out[outpos++] = i;
+       out[outpos++] = l;
 
        /* store target buffer size */
-       i = trg_size;
-       while (i >= 0x80) {
-               out[outpos++] = i | 0x80;
-               i >>= 7;
+       l = trg_size;
+       while (l >= 0x80) {
+               out[outpos++] = l | 0x80;
+               l >>= 7;
        }
-       out[outpos++] = i;
+       out[outpos++] = l;
 
        ref_data = index->src_buf;
        ref_top = ref_data + index->src_size;
@@ -445,6 +454,9 @@ create_delta(const struct delta_index *index,
                        moff += msize;
                        msize = left;
 
+                       if (moff > 0xffffffff)
+                               msize = 0;
+
                        if (msize < 4096) {
                                int j;
                                val = 0;