[PATCH 11/15] midx: use 64-bit multiplication for chunk sizes
- From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Dec 3, 2020, 16:16 UTC
- Message-ID
- <c6a433efba3214e83a7265e53c24cb4001345f14.1607012215.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.804.git.1607012215.gitgitgadget@gmail.com>
From: Derrick Stolee <dstolee@microsoft.com>
When calculating the sizes of certain chunks, we should use 64-bit multiplication always. This allows us to properly predict the chunk sizes without risk of overflow.
Signed-off-by: Derrick Stolee <dstolee@microsoft.com> --- midx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/midx.c b/midx.c index 0548266bea..47f5f60fcd 100644 --- a/midx.c +++ b/midx.c @@ -946,12 +946,12 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * chunks[2].write_fn = write_midx_oid_lookup; chunks[3].id = MIDX_CHUNKID_OBJECTOFFSETS; - chunks[3].size = ctx.entries_nr * MIDX_CHUNK_OFFSET_WIDTH; + chunks[3].size = (uint64_t)ctx.entries_nr * MIDX_CHUNK_OFFSET_WIDTH; chunks[3].write_fn = write_midx_object_offsets; if (ctx.large_offsets_needed) { chunks[4].id = MIDX_CHUNKID_LARGEOFFSETS; - chunks[4].size = ctx.num_large_offsets * MIDX_CHUNK_LARGE_OFFSET_WIDTH; + chunks[4].size = (uint64_t)ctx.num_large_offsets * MIDX_CHUNK_LARGE_OFFSET_WIDTH; chunks[4].write_fn = write_midx_large_offsets; }
-- gitgitgadget