]> git.ipfire.org Git - thirdparty/git.git/commit
pack-bitmap.c: ensure that eindex lookups don't overflow
authorTaylor Blau <me@ttaylorr.com>
Wed, 12 Jul 2023 23:37:52 +0000 (19:37 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Jul 2023 16:32:03 +0000 (09:32 -0700)
commit0948c501761585bdf3e4e1133700c2eb867d88e6
tree32002a750880b2e9a479ad463ee7d378d048ea17
parentd67609bdded151d78522911629c9e7da7fd06640
pack-bitmap.c: ensure that eindex lookups don't overflow

When a bitmap is used to answer some reachability query, it creates a
pseudo-bitmap called the "extended index" on top of any existing bitmaps
to store objects that are relevant to the query, but not mentioned in
the bitmap.

When looking up the ith object in the extended index in a bitmap, it is
common to write something like:

    bitmap_get(result, i + bitmap_num_objects(bitmap_git))

, indicating that we want the ith object following all other objects
mentioned in the bitmap_git.

Since the type of `i` and the return type of `bitmap_num_objects()` are
both `uint32_t`s,  But if there are either a large number of objects in
the bitmap, or a large number of objects in the extended index (or
both), this addition can overflow when the sum is greater than 2^32-1.

Having that large of a bitmap position is entirely acceptable, but we
need to ensure that the computed bitmap position for that object is
performed using 64-bits and doesn't overflow.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pack-bitmap.c