* >4GiB source delta assertion failure
@ 2010-07-21 23:16 Ilari Liusvaara
2010-08-21 5:00 ` [PATCH] fix " Nicolas Pitre
0 siblings, 1 reply; 2+ messages in thread
From: Ilari Liusvaara @ 2010-07-21 23:16 UTC (permalink / raw)
To: git
Yes, I know trying to delta-compress with 4GiB files is insane, but OTOH,
assertion failures are bugs by defintion.
Delta source: <4GiB of zeroes> <random 64KiB block>
Delta destination: <the same 64KiB block>
This was created using:
$ dd if=/dev/urandom of=test-delta-target bs=64k count=1
$ dd if=test-delta-target of=test-delta-source bs=64k seek=64k
Now running
$ ./test-delta -d test-delta-source test-delta-target test-delta-delta
Crashes with (v1.7.2):
test-delta: diff-delta.c:285: create_delta_index: Assertion `packed_entry - (struct index_entry *)mem == entries' failed.
Aborted
As note: The delta compression format does not allow delta compression to
properly work in this case (since source offset would need to be 2^32 and
biggest possible offset is 2^32-1), and thus the size of output should be on
order of 66kB.
-Ilari
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] fix >4GiB source delta assertion failure
2010-07-21 23:16 >4GiB source delta assertion failure Ilari Liusvaara
@ 2010-08-21 5:00 ` Nicolas Pitre
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Pitre @ 2010-08-21 5:00 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Ilari Liusvaara, git
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>
---
diff --git a/diff-delta.c b/diff-delta.c
index 464ac3f..73acf8a 100644
--- a/diff-delta.c
+++ b/diff-delta.c
@@ -146,7 +146,14 @@ 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++);
hsize = 1 << i;
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-08-21 5:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-21 23:16 >4GiB source delta assertion failure Ilari Liusvaara
2010-08-21 5:00 ` [PATCH] fix " Nicolas Pitre
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).