On Thu, Oct 15, 2009 at 09:39, Junio C Hamano <gitster@xxxxxxxxx> wrote: > Nicolas Pitre <nico@xxxxxxxxxxx> writes: > >> I confirm this test without the fix reproduces the infinite loop (and >> does stall the test suite). > > Thanks, both of you. I seem to have problems with this change (on Cygwin). Sometimes accessing an object in a pack fails in unpack_compressed_entry. When it happens, both avail_in and avail_out of the stream are 0, and the reported status is Z_BUF_ERROR. Output with the second attached patch: error: *** inflate error: 0x862380 size=1256, avail_in=0 (was 697), avail_out=0 (was 1256) error: *** unpack_compressed_entry failed error: failed to read object 3296766eb5531ef051ae392114de5d75556f5613 at offset 2620741 from .git/objects/pack/pack-996206790aaefbf4d34c86b3ff546bb924546b7c.pack fatal: object 3296766eb5531ef051ae392114de5d75556f5613 is corrupted I cannot reproduce the problem on a normal system (a 64bit, reasonably modern Linux in my case). An attempt to use an upgraded zlib on this cygwin system was not successful, there was an updated library, but a clean recompile didn't change anything. I worked the case around by allocating a bit more than uncompressed data need. In case someone else also sees the problem, below is how. The size of the overallocation is arbitrary. diff --git a/sha1_file.c b/sha1_file.c index 4cc8939..66c2519 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1585,11 +1585,11 @@ static void *unpack_compressed_entry(struct packed_git *p, z_stream stream; unsigned char *buffer, *in; - buffer = xmalloc(size + 1); - buffer[size] = 0; + buffer = xmalloc(size + 8); + memset(buffer + size, 0, 8); memset(&stream, 0, sizeof(stream)); stream.next_out = buffer; - stream.avail_out = size; + stream.avail_out = size + 8; git_inflate_init(&stream); do { -- 1.6.5.59.g000dd The problematic repo is a little big to post (it's my cygwin-git repo), I'll have to find hosting for it first.
Attachment:
0001-Workaround-inflate-sometimes-failing-to-unpack-data.diff
Description: Binary data
Attachment:
0002-Debugging-strange-failure-in-zlibs-inflate.diff
Description: Binary data