Skip to content

Prepare for v2.47.0.windows.2 #5221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
unpack-trees: detect mismatching number of cache-tree/index entries
Same as the preceding commit, we unconditionally dereference the index's
cache entries depending on the number of cache-tree entries, which can
lead to a segfault when the cache-tree is corrupted. Fix this bug.

This also makes t4058 pass with the leak sanitizer enabled.

Signed-off-by: Patrick Steinhardt <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
pks-t authored and dscho committed Oct 21, 2024
commit 7959bb658d8e0fc852973b13bf32c4afb8a6fc92
7 changes: 5 additions & 2 deletions t/t4058-diff-duplicates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# that the diff output isn't wildly unreasonable.

test_description='test tree diff when trees have duplicate entries'

TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh

# make_tree_entry <mode> <mode> <sha1>
Expand Down Expand Up @@ -143,11 +145,12 @@ test_expect_success 'reset --hard does not segfault' '
test_grep "error: corrupted cache-tree has entries not present in index" err
'

test_expect_failure 'git diff HEAD does not segfault' '
test_expect_success 'git diff HEAD does not segfault' '
git checkout base &&
GIT_TEST_CHECK_CACHE_TREE=false &&
git reset --hard &&
test_might_fail git diff HEAD
test_must_fail git diff HEAD 2>err &&
test_grep "error: corrupted cache-tree has entries not present in index" err
'

test_expect_failure 'can switch to another branch when status is empty' '
Expand Down
2 changes: 2 additions & 0 deletions unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,8 @@ static int traverse_by_cache_tree(int pos, int nr_entries, int nr_names,

if (!o->merge)
BUG("We need cache-tree to do this optimization");
if (nr_entries + pos > o->src_index->cache_nr)
return error(_("corrupted cache-tree has entries not present in index"));

/*
* Do what unpack_callback() and unpack_single_entry() normally
Expand Down