diff options
author | Phillip Wood <phillip.wood@dunelm.org.uk> | 2025-05-22 16:55:20 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2025-05-22 14:48:36 -0700 |
commit | b103881d4f4b157d86813ba5f91acd7ed6c888d0 (patch) | |
tree | 3e4114cdfa25c18e0e3591100889bc414745bdce /builtin/commit-tree.c | |
parent | 8613c2bb6cd16ef530dc5dd74d3b818a1ccbf1c0 (diff) |
midx repack: avoid integer overflow on 32 bit systems
On a 32 bit system "git multi-pack-index --repack --batch-size=120M"
failed with
fatal: size_t overflow: 6038786 * 1289
The calculation to estimated size of the objects in the pack referenced
by the multi-pack-index uses st_mult() to multiply the pack size by the
number of referenced objects before dividing by the total number of
objects in the pack. As size_t is 32 bits on 32 bit systems this
calculation easily overflows. Fix this by using 64bit arithmetic instead.
Also fix a potential overflow when caluculating the total size of the
objects referenced by the multipack index with a batch size larger
than SIZE_MAX / 2. In that case
total_size += estimated_size
can overflow as both total_size and estimated_size can be greater that
SIZE_MAX / 2. This is addressed by using saturating arithmetic for the
addition. Although estimated_size is of type uint64_t by the time we
reach this sum it is bounded by the batch size which is of type size_t
and so casting estimated_size to size_t does not truncate the value.
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/commit-tree.c')
0 files changed, 0 insertions, 0 deletions