sha1_file.c: do not die failing to malloc in unpack_compressed_entry
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>
Nguyễn Thái Ngọc Duy committed
Aug 16, 2014 at 10:08 UTC
735efde838b68747e737e863427a4843a8efaddb
2 files changed
+9
-1
sha1_file.c
+3
-1
@@ -1923,7 +1923,9 @@ static void *unpack_compressed_entry(struct packed_git *p,
1923
git_zstream stream;
1924
unsigned char *buffer, *in;
1925
1926
- buffer = xmallocz(size);
1926
+ buffer = xmallocz_gently(size);
1927
+ if (!buffer)
1928
+ return NULL;
1929
memset(&stream, 0, sizeof(stream));
1930
stream.next_out = buffer;
1931
stream.avail_out = size + 1;
t/t1050-large.sh
+6
@@ -163,4 +163,10 @@ test_expect_success 'zip achiving, deflate' '
163
git archive --format=zip HEAD >/dev/null
164
'
165
166
+test_expect_success 'fsck' '
167
+ test_must_fail git fsck 2>err &&
168
+ n=$(grep "error: attempting to allocate .* over limit" err | wc -l) &&
169
+ test "$n" -gt 1
170
+'
171
+
172
test_done