diff options
| author | Junio C Hamano <gitster@pobox.com> | 2024-11-20 14:42:58 +0900 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-11-20 14:42:59 +0900 |
| commit | 257f2de9644536964c02eed53271df89e132d4f4 (patch) | |
| tree | aab2dc6fa6d86b450689a87bd892d5d27f5b27c2 /unpack-trees.c | |
| parent | 76c1953395770e5334a506eb59bc19ff4cd99e6c (diff) | |
| parent | ecb5c4318cd8b5bbb72f943b6128fe946ffcb56e (diff) | |
| download | git-257f2de9644536964c02eed53271df89e132d4f4.tar.gz | |
Merge branch 'ps/cache-tree-w-broken-index-entry' into maint-2.47
Fail gracefully instead of crashing when attempting to write the
contents of a corrupt in-core index as a tree object.
* ps/cache-tree-w-broken-index-entry:
unpack-trees: detect mismatching number of cache-tree/index entries
cache-tree: detect mismatching number of index entries
cache-tree: refactor verification to return error codes
Diffstat (limited to 'unpack-trees.c')
| -rw-r--r-- | unpack-trees.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/unpack-trees.c b/unpack-trees.c index 9a55cb6204..e10a9d1209 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -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 @@ -2070,9 +2072,13 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options if (o->dst_index) { move_index_extensions(&o->internal.result, o->src_index); if (!ret) { - if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0)) - cache_tree_verify(the_repository, - &o->internal.result); + if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0) && + cache_tree_verify(the_repository, + &o->internal.result) < 0) { + ret = -1; + goto done; + } + if (!o->skip_cache_tree_update && !cache_tree_fully_valid(o->internal.result.cache_tree)) cache_tree_update(&o->internal.result, |
