Skip to content

Commit 168a937

Browse files
avargitster
authored andcommitted
object-file: fix SEGV on free() regression in v2.34.0-rc2
Fix a regression introduced in my 96e41f5 (fsck: report invalid object type-path combinations, 2021-10-01). When fsck-ing blobs larger than core.bigFileThreshold, we'd free() a pointer to uninitialized memory. This issue would have been caught by SANITIZE=address, but since it involves core.bigFileThreshold, none of the existing tests in our test suite covered it. Running them with the "big_file_threshold" in "environment.c" changed to say "6" would have shown this failure, but let's add a dedicated test for this scenario based on Han Xin's report[1]. The bug was introduced between v9 and v10[2] of the fsck series merged in 061a21d (Merge branch 'ab/fsck-unexpected-type', 2021-10-25). 1. https://lore.kernel.org/git/[email protected]/ 2. https://lore.kernel.org/git/[email protected]/ Reported-by: Han Xin <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 96e41f5 commit 168a937

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

object-file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,8 @@ int read_loose_object(const char *path,
25332533
char hdr[MAX_HEADER_LEN];
25342534
unsigned long *size = oi->sizep;
25352535

2536+
*contents = NULL;
2537+
25362538
map = map_loose_object_1(the_repository, path, NULL, &mapsize);
25372539
if (!map) {
25382540
error_errno(_("unable to mmap %s"), path);

t/t1050-large.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ test_expect_success setup '
1717
export GIT_ALLOC_LIMIT
1818
'
1919

20+
test_expect_success 'enter "large" codepath, with small core.bigFileThreshold' '
21+
test_when_finished "rm -rf repo" &&
22+
23+
git init --bare repo &&
24+
echo large | git -C repo hash-object -w --stdin &&
25+
git -C repo -c core.bigfilethreshold=4 fsck
26+
'
27+
2028
# add a large file with different settings
2129
while read expect config
2230
do

0 commit comments

Comments
 (0)