Skip to content

Commit e162aed

Browse files
ttaylorrgitster
authored andcommitted
pack-revindex.c: guard against out-of-bounds pack lookups
The function midx_key_to_pack_pos() is a helper function used by midx_to_pack_pos() and midx_pair_to_pack_pos() to translate a (pack, offset) tuple into a position into the MIDX pseudo-pack order. Ensure that the pack ID given to midx_pair_to_pack_pos() is bounded by the number of packs within the MIDX to prevent, for instance, uninitialized memory from being used as a pack ID. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ed4a1d6 commit e162aed

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pack-revindex.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ static int midx_key_to_pack_pos(struct multi_pack_index *m,
527527
{
528528
uint32_t *found;
529529

530+
if (key->pack >= m->num_packs)
531+
BUG("MIDX pack lookup out of bounds (%"PRIu32" >= %"PRIu32")",
532+
key->pack, m->num_packs);
530533
/*
531534
* The preferred pack sorts first, so determine its identifier by
532535
* looking at the first object in pseudo-pack order.

0 commit comments

Comments
 (0)