Re: [PATCH v2] diff-delta: use safe integer arithmetic
- From
- Srujith Poojary <poojarysrujith@gmail.com>
- Date
- Oct 24, 2026, 03:44 UTC
- Message-ID
- <CABh_KWj9wbanf6MSscwfurkgsaSgJvL_tg17sTt69TfWufnVyQ@mail.gmail.com>
- In-Reply-To
- <xmqq8q3o5k1q.fsf@gitster.g>
On Sat, Oct 24, 2026 at 12:19 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 13 quoted lines
> > Phillip Wood <phillip.wood123@gmail.com> writes: > > >> + memsize = st_add3(sizeof(*index), > >> + st_mult(sizeof(*packed_hash), hsize + 1), > > > > What are the bounds of hsize? Can adding one to it overflow? The > > alignment is off here as well, all the arguments to st_add3() should be > > aligned. > > Very good question, and I think hsize is capped at 1^26 in a code > early in this function, which makes this safe. It needs to be > explained why it is safe in the log message, though.
Hi Junio,
Thank you for analyzing the struct alignment and memory allocation limits. I have updated the commit message to explain why st_mult/st_add are necessary on 32-bit platforms due to padding, as well as documenting that hsize + 1 is safe because hsize is capped at 2^26. I also fixed the code formatting using git clang-format HEAD^.
Best regards, Srujith