From: Andreas Gal Date: Sun, 24 Apr 2005 21:04:13 +0000 (-0700) Subject: [PATCH] fix segfault in fsck-cache X-Git-Tag: v0.99~759 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=da6abf5d9c342a74dffbcc2015b9c27d7819a900;p=git.git [PATCH] fix segfault in fsck-cache Here is how to trigger it: echo blob 100 > .git/objects/00/ae4e8d3208e09f2cf7a38202a126f728cadb49 Then run fsck-cache. It will try to unpack after the header to calculate the hash, inflate returns total_out == 0 and memcpy() dies. The patch below seems to work with ZLIB 1.1 and 1.2. Signed-off-by: Andreas Gal Signed-off-by: Linus Torvalds --- diff --git a/sha1_file.c b/sha1_file.c index 97a515a07..28ad1598e 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -155,6 +155,8 @@ void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned l inflateInit(&stream); ret = inflate(&stream, 0); + if (ret < Z_OK) + return NULL; if (sscanf(buffer, "%10s %lu", type, size) != 2) return NULL;