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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
# 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>
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' '
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