From 6fff9917f958d4a6ddc4ba6359fe75d029bf71f1 Mon Sep 17 00:00:00 2001 From: Jeremy Linton Date: Wed, 13 Jun 2018 09:22:07 -0500 Subject: [PATCH] sha1_file: correct zlib buffer handling The buffer being passed to zlib includes a NUL terminator that git needs to keep in place. unpack_compressed_entry() attempts to detect the case that the source buffer hasn't been fully consumed by checking to see if the destination buffer has been over consumed. This causes a problem, that more recent zlib patches have been poisoning the unconsumed portions of the buffer which overwrites the NUL byte, while correctly returning length and status. Let's place the NUL at the end of the buffer after inflate returns to assure that it doesn't result in problems for git even if its been overwritten by zlib. Signed-off-by: Jeremy Linton Signed-off-by: Junio C Hamano --- sha1_file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sha1_file.c b/sha1_file.c index 1173071859..4ff9209a4f 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2247,6 +2247,9 @@ static void *unpack_compressed_entry(struct packed_git *p, return NULL; } + /* versions of zlib can clobber unconsumed portion of outbuf */ + buffer[size] = '\0'; + return buffer; } -- 2.11.4.GIT