]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: correct zlib buffer handling
authorJeremy Linton <lintonrjeremy@gmail.com>
Wed, 13 Jun 2018 14:22:07 +0000 (09:22 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 Jun 2018 18:34:27 +0000 (11:34 -0700)
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 <lintonrjeremy@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
packfile.c

index 4a5fe7ab1883843a389ce74bf1c7bd89890d8e51..d55569921793ed8f16efef2d6908740888a06b4d 100644 (file)
@@ -1422,6 +1422,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;
 }