Skip to content

Commit 9064d87

Browse files
spearcegitster
authored andcommitted
Don't segfault if we failed to inflate a packed delta
Under some types of packfile corruption the zlib stream holding the data for a delta within a packfile may fail to inflate, due to say a CRC failure within the compressed data itself. When this occurs the unpack_compressed_entry function will return NULL as a signal to the caller that the data is not available. Unfortunately we then tried to use that NULL as though it referenced a memory location where a delta was stored and tried to apply it to the delta base. Loading a byte from the NULL address typically causes a SIGSEGV. cate on #git noticed this failure in `git fsck --full` where the call to verify_pack() first noticed that the packfile was corrupt by finding that the packfile's SHA-1 did not match the raw data of the file. After finding this fsck went ahead and tried to verify every object within the packfile, even though the packfile was already known to be bad. If we are going to shovel bad data at the delta unpacking code, we better handle it correctly. Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2e3404c commit 9064d87

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

sha1_file.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,10 @@ static void *unpack_delta_entry(struct packed_git *p,
15701570
(uintmax_t)base_offset, p->pack_name);
15711571

15721572
delta_data = unpack_compressed_entry(p, w_curs, curpos, delta_size);
1573+
if (!delta_data)
1574+
die("failed to unpack compressed delta"
1575+
" at %"PRIuMAX" from %s",
1576+
(uintmax_t)curpos, p->pack_name);
15731577
result = patch_delta(base, base_size,
15741578
delta_data, delta_size,
15751579
sizep);

0 commit comments

Comments
 (0)