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

Re: [PATCH 1/4] midx repack: avoid integer overflow on 32 bit systems

From
Taylor Blau <me@ttaylorr.com>
Date
May 23, 2025, 00:34 UTC
Message-ID
<aC/CmFzz397p7hFz@nand.local>
In-Reply-To
<a87e6f8f-e6b3-4d91-8b0a-312962819eb4@gmail.com>
On Wed, May 21, 2025 at 04:19:59PM +0100, Phillip Wood wrote:
Show 25 quoted lines
> > >   		expected_size /= p->num_objects;
> > >
> > >   		if (expected_size >= batch_size)
> > >   			continue;
> > >
> > > -		total_size += expected_size;
> > > +		if (unsigned_add_overflows (total_size, (size_t)expected_size))
> > > +			total_size = SIZE_MAX;
> > > +		else
> > > +			total_size += expected_size;
> > > +
> >
> > But this part I am not totally following. Here we have 'total_size'
> > declared as a size_t, and 'expected_size' as a uint64_t, and (on 32-bit
> > systems) down-cast to a 32-bit unsigned value.
> >
> > So if 'expected_size' is larger than SIZE_MAX, we should set
> > 'total_size' to SIZE_MAX. But that may not happen, say if
> > 'expected_size' is (2^32-1<<32). Should total_size also be declared as a
> > uint64_t here?
>
> By this point we know that expected_size < SIZE_MAX due to the test in the
> context lines above this change. batch_size is declared as size_t and to get
> here expected_size < batch_size. I'll add a sentence to the commit message
> to make that clearer.

Ahh... makes sense. I don't think a comment is necessary, this should have been obvious. The check you're referring to gives us the fact that

    expected_size < batch_size <= SIZE_MAX
So we're OK here; sorry for missing that!

Thanks, Taylor

Previous: Phillip WoodNext: D. Ben Knoble
Message 5 of 25 in “midx repack: fix overflow on 32 bit systems”
  1. 0/4 midx repack: fix overflow on 32 bit systemsPhillip Wood, May 20, 2025
  2. 1/4 midx repack: avoid integer overflow on 32 bit systemsPhillip Wood, May 20, 2025
  3. Taylor BlauMay 20, 2025
  4. Phillip WoodMay 21, 2025
  5. Taylor BlauMay 23, 2025
  6. D. Ben KnobleMay 21, 2025
  7. Junio C HamanoMay 21, 2025
  8. Phillip WoodMay 21, 2025
  9. 2/4 midx repack: avoid potential integer overflow on 64 bit systemsPhillip Wood, May 20, 2025
  10. Taylor BlauMay 20, 2025
  11. Phillip WoodMay 21, 2025
  12. 3/4 midx: avoid negative array indexPhillip Wood, May 20, 2025
  13. Taylor BlauMay 20, 2025
  14. 4/4 midx docs: clarify tie breakingPhillip Wood, May 20, 2025
  15. Taylor BlauMay 20, 2025
  16. Phillip WoodMay 21, 2025
  17. D. Ben KnobleMay 21, 2025
  18. 0/4 midx repack: fix overflow on 32 bit systemsPhillip Wood, May 22, 2025
  19. 2/4 midx repack: avoid potential integer overflow on 64 bit systemsPhillip Wood, May 22, 2025
  20. 1/4 midx repack: avoid integer overflow on 32 bit systemsPhillip Wood, May 22, 2025
  21. 3/4 midx: avoid negative array indexPhillip Wood, May 22, 2025
  22. 4/4 midx docs: clarify tie breakingPhillip Wood, May 22, 2025
  23. Taylor BlauMay 23, 2025
  24. Phillip WoodMay 27, 2025
  25. Junio C HamanoMay 27, 2025

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.