Re: [PATCH 11/15] midx: use 64-bit multiplication for chunk sizes
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 3, 2020, 22:00 UTC
- Message-ID
- <xmqqa6uuh7n1.fsf@gitster.c.googlers.com>
- In-Reply-To
- <c6a433efba3214e83a7265e53c24cb4001345f14.1607012215.git.gitgitgadget@gmail.com>
"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
> 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.
That's quite an obvious fix, applicable even before this entire series. I think we saw quite similar bugfixes in different parts of the codebase recently.
So far, everything looks good.
Show 23 quoted lines
> 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;
> }