summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-02-14 20:42:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-02-14 20:42:28 (GMT)
commit5ae057d9a8c79fea1ad58658660d9fe42668e972 (patch)
treefaac78a5ef54762f3a7983d76d9354711a0b868a
parentc17cf77e4e021194f52f32b0b8def06c7933e89f (diff)
parent573117dfa597215fbf9a3d73b7f9c71c280c684f (diff)
downloadgit-5ae057d9a8c79fea1ad58658660d9fe42668e972.zip
git-5ae057d9a8c79fea1ad58658660d9fe42668e972.tar.gz
git-5ae057d9a8c79fea1ad58658660d9fe42668e972.tar.bz2
Merge branch 'es/unpack-trees-oob-fix' into maint
The code that tries to skip over the entries for the paths in a single directory using the cache-tree was not careful enough against corrupt index file. * es/unpack-trees-oob-fix: unpack-trees: watch for out-of-range index position
-rw-r--r--unpack-trees.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/unpack-trees.c b/unpack-trees.c
index 2399b68..2f4e2e4 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -694,9 +694,11 @@ static int index_pos_by_traverse_info(struct name_entry *names,
if (pos >= 0)
BUG("This is a directory and should not exist in index");
pos = -pos - 1;
- if (!starts_with(o->src_index->cache[pos]->name, name.buf) ||
+ if (pos >= o->src_index->cache_nr ||
+ !starts_with(o->src_index->cache[pos]->name, name.buf) ||
(pos > 0 && starts_with(o->src_index->cache[pos-1]->name, name.buf)))
- BUG("pos must point at the first entry in this directory");
+ BUG("pos %d doesn't point to the first entry of %s in index",
+ pos, name.buf);
strbuf_release(&name);
return pos;
}