git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] [Outreachy PATCH] diff-delta: use safe integer arithmetic

From
SPSrujith Poojary <poojarysrujith@gmail.com>
Date
Oct 23, 2026, 16:56 UTC
Message-ID
<CABh_KWgBzCXCSn4FUTSg+rXYj9vm6+AVZnDn3iR_4UJCsB8tjw@mail.gmail.com>
In-Reply-To
<xmqqtsmca0yy.fsf@gitster.g>
On Fri, Oct 23, 2026 at 9:00 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 26 quoted lines
>
> 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.
>
Hi Phillip and Junio,
Thank you for the detailed feedback.

I checked the bounds: since entries is capped by (0xffffffu / RABIN_WINDOW), hsize remains small, making a size_t overflow impossible even on 32-bit systems.

I ran git clang-format HEAD^ to fix the code alignment as suggested and updated the patch.

Best regards, Srujith

Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 31 in “diff-delta: use safe integer arithmetic”
  1. [Outreachy PATCH] diff-delta: use safe integer arithmeticSrujith A Poojary via GitGitGadget, Oct 23, 2026
  2. Junio C HamanoOct 23, 2026
  3. Srujith PoojaryOct 23, 2026
  4. Junio C HamanoOct 23, 2026
  5. Srujith PoojaryOct 23, 2026
  6. Junio C HamanoOct 23, 2026
  7. diff-delta: use safe integer arithmeticSrujith A Poojary via GitGitGadget, Oct 23, 2026
  8. Phillip WoodOct 23, 2026
  9. Junio C HamanoOct 23, 2026
  10. Srujith PoojaryOct 24, 2026
  11. diff-delta: use safe integer arithmeticSrujith A Poojary via GitGitGadget, Oct 24, 2026
  12. Junio C HamanoOct 24, 2026
  13. Srujith PoojaryOct 24, 2026
  14. Junio C HamanoOct 25, 2026
  15. Srujith PoojaryOct 25, 2026
  16. diff-delta: use safe integer arithmeticSrujith A Poojary via GitGitGadget, Oct 24, 2026
  17. diff-delta: use safe integer arithmeticSrujith A Poojary via GitGitGadget, Oct 25, 2026
  18. Junio C HamanoOct 26, 2026
  19. Srujith PoojaryOct 26, 2026
  20. Srujith PoojaryOct 27, 2026
  21. diff-delta: use safe integer arithmeticSrujith A Poojary via GitGitGadget, Oct 27, 2026
  22. Pablo SabaterOct 27, 2026
  23. Srujith PoojaryOct 27, 2026
  24. Pablo SabaterOct 27, 2026
  25. diff-delta: use safe integer arithmeticSrujith A Poojary via GitGitGadget, Oct 27, 2026
  26. Pablo SabaterOct 27, 2026
  27. Srujith PoojaryOct 27, 2026
  28. Junio C HamanoOct 27, 2026
  29. Srujith PoojaryOct 27, 2026
  30. diff-delta: use safe integer arithmeticSrujith A Poojary via GitGitGadget, Oct 27, 2026
  31. diff-delta: use safe integer arithmeticSrujith A Poojary via GitGitGadget, Oct 27, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.