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

[RFC] 'unsigned long' to 'size_t' conversion

From
Derrick Stolee <stolee@gmail.com>
Date
Dec 6, 2017, 15:08 UTC
Message-ID
<a660460d-b294-5113-bfaf-d98bcf99bad5@gmail.com>

There are several places in Git where we refer to the size of an object by an 'unsigned long' instead of a 'size_t'. In 64-bit Linux, 'unsigned long' is 8 bytes, but in 64-bit Windows it is 4 bytes.

The main issue with this conversion is that large objects fail to load (they seem to hash and store just fine). For example, the following 'blob8gb' is an 8 GB file where the ith byte is equal to i % 256:

$ git hash-object -w --no-filters blob8gb 5391939346b98600acc0283dda24649450cec51f

$ git cat-file -s 5391939346b98600acc0283dda24649450cec51f error: bad object header fatal: git cat-file: could not get object info

An existing discussion can be found here: https://github.com/git-for-windows/git/issues/1063

The error message results from unpack_object_header_buffer() which had its most-recent meaningful change in 'ea4f9685: unpack_object_header_buffer(): clear the size field upon error' (in 2011).

In my opinion, the correct thing to do would be to replace all 'unsigned long's that refer to an object size and replace them with 'size_t'. However, a simple "git grep 'unsigned long size'" reveals 194 results, and there are other permutations of names and pointer types all over.

This conversion would be a significant patch, so I wanted to get the community's thoughts on this conversion.

If there are small, isolated chunks that can be done safely, then this may be a good target for a first patch.

Thanks,
-Stolee
Next: Thomas Braun
Message 1 of 4 in “[RFC] 'unsigned long' to 'size_t' conversion”
  1. Derrick StoleeDec 6, 2017
  2. Thomas BraunDec 6, 2017
  3. Brandon WilliamsDec 6, 2017
  4. Jeff KingDec 6, 2017

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.