{"thread":{"id":"24462","subject":">4GiB source delta assertion failure","startedAt":"2010-07-21T23:16:35Z","lastAt":"2010-08-21T05:00:13Z","messageCount":2,"participants":["Ilari Liusvaara","Nicolas Pitre"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"145970","messageId":"20100721231635.GA6387@LK-Perkele-V2.elisa-laajakaista.fi","threadId":"24462","inReplyTo":null,"subject":">4GiB source delta assertion failure","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-07-21T23:16:35Z","receivedAt":"2010-07-21T23:16:35Z","isPatch":false,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"Yes, I know trying to delta-compress with 4GiB files is insane, but OTOH,\nassertion failures are bugs by defintion.\n\nDelta source: <4GiB of zeroes> <random 64KiB block>\nDelta destination: <the same 64KiB block>\n\nThis was created using:\n$ dd if=/dev/urandom of=test-delta-target bs=64k count=1\n$ dd if=test-delta-target of=test-delta-source bs=64k seek=64k\n\nNow running\n\n$ ./test-delta -d test-delta-source test-delta-target test-delta-delta\n\nCrashes with (v1.7.2):\n\ntest-delta: diff-delta.c:285: create_delta_index: Assertion `packed_entry - (struct index_entry *)mem == entries' failed.\nAborted\n\n\nAs note: The delta compression format does not allow delta compression to \nproperly work in this case (since source offset would need to be 2^32 and\nbiggest possible offset is 2^32-1), and thus the size of output should be on\norder of 66kB.\n\n-Ilari\n"},{"id":"148637","messageId":"alpine.LFD.2.00.1008202349500.622@xanadu.home","threadId":"24462","inReplyTo":"20100721231635.GA6387@LK-Perkele-V2.elisa-laajakaista.fi","subject":"[PATCH] fix >4GiB source delta assertion failure","fromName":"Nicolas Pitre","fromEmail":"nico@fluxnic.net","sentAt":"2010-08-21T05:00:13Z","receivedAt":"2010-08-21T05:00:13Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"When people try insane things such as delta-compressing 4GiB files, they\nget this assertion:\n\ndiff-delta.c:285: create_delta_index: Assertion `packed_entry - (struct index_entry *)mem == entries' failed.\n\nThis happens because:\n\n1) the 'entries' variable is an unsigned int\n\n2) it is assigned with entries = (bufsize - 1) / RABIN_WINDOW\n   (that itself is not a problem unless bufsize > 4G * RABIN_WINDOW)\n\n3) the buffer is indexed from top to bottom starting at\n   \"data = buffer + entries * RABIN_WINDOW\" and the multiplication\n   here does indeed overflows, making the resulting top of the buffer \n   much lower than expected.\n\nThis makes the number of actually produced index entries smaller than \nwhat was computed initially, hence the assertion.\n\nFurthermore, the current delta encoding format cannot represent offsets\ninto a reference buffer with more than 32 bits anyway.  So let's just \nlimit the number of entries to what the delta format can encode.\n\nReported-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>\nSigned-off-by: Nicolas Pitre <nico@fluxnic.net>\n---\ndiff --git a/diff-delta.c b/diff-delta.c\nindex 464ac3f..73acf8a 100644\n--- a/diff-delta.c\n+++ b/diff-delta.c\n@@ -146,7 +146,14 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)\n \t/* Determine index hash size.  Note that indexing skips the\n \t   first byte to allow for optimizing the Rabin's polynomial\n \t   initialization in create_delta(). */\n-\tentries = (bufsize - 1)  / RABIN_WINDOW;\n+\tentries = (bufsize - 1) / RABIN_WINDOW;\n+\tif (bufsize >= 0xffffffffUL) {\n+\t\t/* \n+\t\t * Current delta format can't encode offsets into\n+\t\t * reference buffer with more than 32 bits.\n+\t\t */\n+\t\tentries = 0xfffffffeU / RABIN_WINDOW;\n+\t}\n \thsize = entries / 4;\n \tfor (i = 4; (1u << i) < hsize && i < 31; i++);\n \thsize = 1 << i;\n"}]}