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

Re: [PATCH 2/4] midx repack: avoid potential integer overflow on 64 bit systems

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
May 21, 2025, 15:20 UTC
Message-ID
<7302bdf8-f713-43eb-aa78-759bb1e1b6b6@gmail.com>
In-Reply-To
<aCzDCEK7OhCYyAZa@nand.local>
On 20/05/2025 18:59, Taylor Blau wrote:
Show 21 quoted lines
> On Tue, May 20, 2025 at 04:04:25PM +0100, Phillip Wood wrote:
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> On a 64 bit system the calculation
>>
>>      p->pack_size * pack_info[i].referenced_objects
>>
>> could overflow. If a pack file contains 2^28 objects with an average
>> compressed size of 1KB then the pack size will be 2^38B. If all of the
>> objects are referenced by the multi-pack index the sum above will
>> overflow. Avoid this by using shifted integer arithmetic and changing
>> the order of the calculation so that the pack size is divided by the
>> total number of objects in the pack before multiplying by the number of
>> objects referenced by the multi-pack index. Using a shift of 14 bits
>> should give reasonable accuracy while avoiding overflow for pack sizes
>> less that 1PB.
> 
> Ahhh, this renders some of comments on the previous patch moot. I think
> that this is a not-unreasonable concern to be addressing even on modern
> 64-bit systems, since I have definitely encountered packs that have on
> the order of ~2^28 objects in them.
Thanks, that's good to know
Phillip
> I like this approach quite a bit, thanks!
> 
> Thanks,
> Taylor
Previous: Taylor BlauNext: Phillip Wood
Message 11 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.