Skip to content

Commit 506049c

Browse files
npitregitster
authored andcommitted
fix >4GiB source delta assertion failure
When people try insane things such as delta-compressing 4GiB files, they get this assertion: diff-delta.c:285: create_delta_index: Assertion `packed_entry - (struct index_entry *)mem == entries' failed. This happens because: 1) the 'entries' variable is an unsigned int 2) it is assigned with entries = (bufsize - 1) / RABIN_WINDOW (that itself is not a problem unless bufsize > 4G * RABIN_WINDOW) 3) the buffer is indexed from top to bottom starting at "data = buffer + entries * RABIN_WINDOW" and the multiplication here does indeed overflows, making the resulting top of the buffer much lower than expected. This makes the number of actually produced index entries smaller than what was computed initially, hence the assertion. Furthermore, the current delta encoding format cannot represent offsets into a reference buffer with more than 32 bits anyway. So let's just limit the number of entries to what the delta format can encode. Reported-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi> Signed-off-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0eb032d commit 506049c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

diff-delta.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,14 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
146146
/* Determine index hash size. Note that indexing skips the
147147
first byte to allow for optimizing the Rabin's polynomial
148148
initialization in create_delta(). */
149-
entries = (bufsize - 1) / RABIN_WINDOW;
149+
entries = (bufsize - 1) / RABIN_WINDOW;
150+
if (bufsize >= 0xffffffffUL) {
151+
/*
152+
* Current delta format can't encode offsets into
153+
* reference buffer with more than 32 bits.
154+
*/
155+
entries = 0xfffffffeU / RABIN_WINDOW;
156+
}
150157
hsize = entries / 4;
151158
for (i = 4; (1u << i) < hsize && i < 31; i++);
152159
hsize = 1 << i;

0 commit comments

Comments
 (0)