Re: [PATCH] [Outreachy PATCH] diff-delta: use safe integer arithmetic
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 23, 2026, 15:30 UTC
- Message-ID
- <xmqqtsmca0yy.fsf@gitster.g>
- In-Reply-To
- <CABh_KWiKmXP4KTgF=k2gGdSvcZXkRipD61AVn+AS7ZgvhcjHWw@mail.gmail.com>
Srujith Poojary <poojarysrujith@gmail.com> writes:
> Thank you for clarifying this. You are right—st_add() and st_mult() > call die() on overflow rather than returning NULL. > I will update the commit message to accurately reflect this behavior > and submit v2.
Please don't, before making sure if it can overflow. With the number of entries capped like this:
if (bufsize >= 0xffffffffUL) entries = 0xfffffffeU / RABIN_WINDOW;
and then computed
hsize = entries / 4; for (i = 4; (1u << i) < hsize; i++); hsize = 1 << i; /* allocate lookup index */ memsize = sizeof(*hash) * hsize + sizeof(*entry) * entries;
it may not be possible to overflow size_t even on 32-bit platforms. I didn't have time to do math yet myself, though.