git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] fix >4GiB source delta assertion failure

From
Nicolas Pitre <nico@fluxnic.net>
Date
Aug 21, 2010, 05:00 UTC
Message-ID
<alpine.LFD.2.00.1008202349500.622@xanadu.home>
In-Reply-To
<20100721231635.GA6387@LK-Perkele-V2.elisa-laajakaista.fi>

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;
Previous: Ilari Liusvaara
Message 2 of 2 in “>4GiB source delta assertion failure”
  1. Ilari LiusvaaraJul 21, 2010
  2. fix >4GiB source delta assertion failureNicolas Pitre, Aug 21, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.