]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-file: fix memory leak when reading corrupted headers
authorPatrick Steinhardt <ps@pks.im>
Wed, 14 Aug 2024 06:51:58 +0000 (08:51 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Aug 2024 17:07:57 +0000 (10:07 -0700)
When reading corrupt object headers in `read_loose_object()`, we bail
out immediately. This causes a memory leak though because we would have
already initialized the zstream in `unpack_loose_header()`, and it is
the callers responsibility to finish the zstream even on error. While
this feels weird, other callsites do it correctly already.

Fix this leak by ending the zstream even on errors. We may want to
revisit this interface in the future such that the callee handles this
for us already when there was an error.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c
t/t1450-fsck.sh

index 065103be3ea923e3fcc87bf5e8e366d202544b14..7c65c435cdaae4e1b037415816e1f4fca065a33f 100644 (file)
@@ -2954,6 +2954,7 @@ int read_loose_object(const char *path,
        if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
                                NULL) != ULHR_OK) {
                error(_("unable to unpack header of %s"), path);
+               git_inflate_end(&stream);
                goto out;
        }
 
index 8a456b1142d1cc463f97c5e8809bcfc83ffa1e96..280cbf3e031e1ab67ed28aa2af4c3b105b7d254e 100755 (executable)
@@ -6,6 +6,7 @@ test_description='git fsck random collection of tests
 * (main) A
 '
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success setup '