diff options
author | Phillip Wood <phillip.wood@dunelm.org.uk> | 2025-05-22 16:55:21 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2025-05-22 14:48:36 -0700 |
commit | f874c0ed90c63276e0ebc445ad6fee5dcbfacb86 (patch) | |
tree | 1dd3569464af917f7d8f7ff35ba5a1adb2bb5343 /builtin/commit-tree.c | |
parent | b103881d4f4b157d86813ba5f91acd7ed6c888d0 (diff) |
midx repack: avoid potential integer overflow on 64 bit systems
On a 64 bit system the calculation
p->pack_size * pack_info[i].referenced_objects
could overflow. If a pack file contains 2^28 objects with an average
compressed size of 1KB then the pack size will be 2^38B. If all of the
objects are referenced by the multi-pack index the sum above will
overflow. Avoid this by using shifted integer arithmetic and changing
the order of the calculation so that the pack size is divided by the
total number of objects in the pack before multiplying by the number of
objects referenced by the multi-pack index. Using a shift of 14 bits
should give reasonable accuracy while avoiding overflow for pack sizes
less that 1PB.
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