Merge branch 'jk/sha1-loose-object-info-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Oct 2017 05:19:14 +0000 (14:19 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Oct 2017 05:19:14 +0000 (14:19 +0900)
Leakfix and futureproofing.

* jk/sha1-loose-object-info-fix:
sha1_loose_object_info: handle errors from unpack_sha1_rest

sha1_file.c
index 9008d6aa7bb59944d97f8ed73d9772d9ab529187..5911364a81fa3d1351fa13d14a63c8854fd60e22 100644 (file)
@@ -2952,10 +2952,14 @@ static int sha1_loose_object_info(const unsigned char *sha1,
        } else if ((status = parse_sha1_header_extended(hdr, oi, flags)) < 0)
                status = error("unable to parse %s header", sha1_to_hex(sha1));
 
-       if (status >= 0 && oi->contentp)
+       if (status >= 0 && oi->contentp) {
                *oi->contentp = unpack_sha1_rest(&stream, hdr,
                                                 *oi->sizep, sha1);
-       else
+               if (!*oi->contentp) {
+                       git_inflate_end(&stream);
+                       status = -1;
+               }
+       } else
                git_inflate_end(&stream);
 
        munmap(map, mapsize);