midx.c: prevent overflow in `nth_midxed_object_oid()`

In a similar spirit as previous commits, avoid overflow when looking up
an object's OID in a MIDX when its position is greater than
`2^32-1/m->hash_len`.

As usual, it is perfectly OK for a MIDX to have as many as 2^32-1
objects (since we use 32-bit fields to count the number of objects at
each fanout layer). But if we have more than `2^32-1/m->hash_len` number
of objects, we will incorrectly perform the computation using 32-bit
integers, overflowing the result.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Taylor Blau 2023-07-12 19:37:38 -04:00 committed by Junio C Hamano
parent e6c71f239d
commit c2b24ede22
1 changed files with 1 additions and 1 deletions

2
midx.c
View File

@ -254,7 +254,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
if (n >= m->num_objects)
return NULL;

oidread(oid, m->chunk_oid_lookup + m->hash_len * n);
oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n));
return oid;
}