diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-01-22 23:07:31 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-01-22 23:07:31 (GMT) |
commit | 36da2a86352cf9db5796dc3d81e8a5571cd5647b (patch) | |
tree | d388da3d082ffbeda7dc4d327bec1d9e9c14722c /unpack-trees.c | |
parent | 42096c778ddfcc946ea6fc302c46f96d586b5bab (diff) | |
parent | 573117dfa597215fbf9a3d73b7f9c71c280c684f (diff) | |
download | git-36da2a86352cf9db5796dc3d81e8a5571cd5647b.zip git-36da2a86352cf9db5796dc3d81e8a5571cd5647b.tar.gz git-36da2a86352cf9db5796dc3d81e8a5571cd5647b.tar.bz2 |
Merge branch 'es/unpack-trees-oob-fix'
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
Diffstat (limited to 'unpack-trees.c')
-rw-r--r-- | unpack-trees.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/unpack-trees.c b/unpack-trees.c index 4c68dbd..d5f4d99 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -696,9 +696,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; } |