Skip to content

Commit 735efde

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f8bb1d9 commit 735efde

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

sha1_file.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,9 @@ static void *unpack_compressed_entry(struct packed_git *p,
19231923
git_zstream stream;
19241924
unsigned char *buffer, *in;
19251925

1926-
buffer = xmallocz(size);
1926+
buffer = xmallocz_gently(size);
1927+
if (!buffer)
1928+
return NULL;
19271929
memset(&stream, 0, sizeof(stream));
19281930
stream.next_out = buffer;
19291931
stream.avail_out = size + 1;

t/t1050-large.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,10 @@ test_expect_success 'zip achiving, deflate' '
163163
git archive --format=zip HEAD >/dev/null
164164
'
165165

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+
166172
test_done

0 commit comments

Comments
 (0)