The same theme as "unpack-objects" patch.
Signed-off-by: Junio C Hamano <redacted>
---
sha1_file.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index 921a216..12a166f 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1643,19 +1643,24 @@ static void *unpack_compressed_entry(struct packed_git *p,
int st;
z_stream stream;
unsigned char *buffer, *in;
+ unsigned long bytes_to_inflate;
buffer = xmallocz(size);
memset(&stream, 0, sizeof(stream));
stream.next_out = buffer;
- stream.avail_out = size + 1;
+ bytes_to_inflate = size + 1;
+ stream.avail_out = zlib_buf_cap(bytes_to_inflate);
git_inflate_init(&stream);
do {
+ unsigned char *out0 = stream.next_out;
in = use_pack(p, w_curs, curpos, &stream.avail_in);
stream.next_in = in;
st = git_inflate(&stream, Z_FINISH);
- if (!stream.avail_out)
+ bytes_to_inflate -= stream.next_out - out0;
+ if (!bytes_to_inflate)
break; /* the payload is larger than it should be */
+ stream.avail_out = zlib_buf_cap(bytes_to_inflate);
curpos += stream.next_in - in;
} while (st == Z_OK || st == Z_BUF_ERROR);
git_inflate_end(&stream);--
1.7.6.rc1.118.ge175b4a