Skip to content

Commit 36da2a8

Browse files
committed
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
2 parents 42096c7 + 573117d commit 36da2a8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

unpack-trees.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,11 @@ static int index_pos_by_traverse_info(struct name_entry *names,
696696
if (pos >= 0)
697697
BUG("This is a directory and should not exist in index");
698698
pos = -pos - 1;
699-
if (!starts_with(o->src_index->cache[pos]->name, name.buf) ||
699+
if (pos >= o->src_index->cache_nr ||
700+
!starts_with(o->src_index->cache[pos]->name, name.buf) ||
700701
(pos > 0 && starts_with(o->src_index->cache[pos-1]->name, name.buf)))
701-
BUG("pos must point at the first entry in this directory");
702+
BUG("pos %d doesn't point to the first entry of %s in index",
703+
pos, name.buf);
702704
strbuf_release(&name);
703705
return pos;
704706
}

0 commit comments

Comments
 (0)