sha1_file.c: do not die failing to malloc in unpack_compressed_entry
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 16 Aug 2014 03:08:03 +0000 (10:08 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 18 Aug 2014 17:15:19 +0000 (10:15 -0700)
Fewer die() gives better control to the caller, provided that the
caller _can_ handle it. And in unpack_compressed_entry() case, it can,
because unpack_compressed_entry() already returns NULL if it fails to
inflate data.

A side effect from this is fsck continues to run when very large blobs
are present (and do not fit in memory).

Noticed-by: Dale R. Worley <worley@alum.mit.edu>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_file.c
t/t1050-large.sh
index 3f70b1d86aaa8e0648d8a3c6ebb6aca701ae7475..8db73f0c53f01bf39decb71d036610d2835cf7ac 100644 (file)
@@ -1923,7 +1923,9 @@ static void *unpack_compressed_entry(struct packed_git *p,
        git_zstream stream;
        unsigned char *buffer, *in;
 
-       buffer = xmallocz(size);
+       buffer = xmallocz_gently(size);
+       if (!buffer)
+               return NULL;
        memset(&stream, 0, sizeof(stream));
        stream.next_out = buffer;
        stream.avail_out = size + 1;
index aea493646e4400e733749768e48f2a3d1a470299..5642f84b8355debe955fe055c85ea6d3ca13c398 100755 (executable)
@@ -163,4 +163,10 @@ test_expect_success 'zip achiving, deflate' '
        git archive --format=zip HEAD >/dev/null
 '
 
+test_expect_success 'fsck' '
+       test_must_fail git fsck 2>err &&
+       n=$(grep "error: attempting to allocate .* over limit" err | wc -l) &&
+       test "$n" -gt 1
+'
+
 test_done