{"thread":{"id":"27597","subject":"[PATCH] unpack_compressed_entry(): zlib can only process 4GB at a time","startedAt":"2011-06-09T20:12:33Z","lastAt":"2011-06-09T20:12:33Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"169809","messageId":"7vvcwewyq6.fsf@alter.siamese.dyndns.org","threadId":"27597","inReplyTo":null,"subject":"[PATCH] unpack_compressed_entry(): zlib can only process 4GB at a time","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-06-09T20:12:33Z","receivedAt":"2011-06-09T20:12:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The same theme as \"unpack-objects\" patch.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n sha1_file.c |    9 +++++++--\n 1 files changed, 7 insertions(+), 2 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 921a216..12a166f 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1643,19 +1643,24 @@ static void *unpack_compressed_entry(struct packed_git *p,\n \tint st;\n \tz_stream stream;\n \tunsigned char *buffer, *in;\n+\tunsigned long bytes_to_inflate;\n \n \tbuffer = xmallocz(size);\n \tmemset(&stream, 0, sizeof(stream));\n \tstream.next_out = buffer;\n-\tstream.avail_out = size + 1;\n+\tbytes_to_inflate = size + 1;\n+\tstream.avail_out = zlib_buf_cap(bytes_to_inflate);\n \n \tgit_inflate_init(&stream);\n \tdo {\n+\t\tunsigned char *out0 = stream.next_out;\n \t\tin = use_pack(p, w_curs, curpos, &stream.avail_in);\n \t\tstream.next_in = in;\n \t\tst = git_inflate(&stream, Z_FINISH);\n-\t\tif (!stream.avail_out)\n+\t\tbytes_to_inflate -= stream.next_out - out0;\n+\t\tif (!bytes_to_inflate)\n \t\t\tbreak; /* the payload is larger than it should be */\n+\t\tstream.avail_out = zlib_buf_cap(bytes_to_inflate);\n \t\tcurpos += stream.next_in - in;\n \t} while (st == Z_OK || st == Z_BUF_ERROR);\n \tgit_inflate_end(&stream);\n-- \n1.7.6.rc1.118.ge175b4a\n"}]}