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

[PATCH 1/3] csum-file: use size_t for the count passed to hashwrite()

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Nov 1, 2026, 15:36 UTC
Message-ID
<07baad46b153b255b6e70f2597f1bf41b9c48dfd.1793546752.git.gitter.spiros@gmail.com>
In-Reply-To
<cover.1793546752.git.gitter.spiros@gmail.com>

hashwrite() takes the byte count as "uint32_t" on all platforms. When pack-objects writes the entire compressed buffer of an object in a single call, which can exceed 4GiB if the object is in memory, poorly compressible and core.bigFileThreshold is raised accordingly, it writes only "count mod 2^32" bytes, corrupting the pack.

This was verified using a 16-bit simulation, where "git cat-file" and "git fsck" failed after "git repack -a -d" with "offset beyond end of packfile (truncated pack?)".

Make the count parameter of hashwrite() a "size_t". The internal loop already handles writing in buffer-sized blocks.

Triggering this requires processing an object of 4GiB or more, so no test is added.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 csum-file.c | 2 +-
 csum-file.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/csum-file.c b/csum-file.c
index fe18ee1de3..26aa662637 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -102,7 +102,7 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
 	return fd;
 }
 
-void hashwrite(struct hashfile *f, const void *buf, uint32_t count)
+void hashwrite(struct hashfile *f, const void *buf, size_t count)
 {
 	while (count) {
 		unsigned left = f->buffer_len - f->offset;
diff --git a/csum-file.h b/csum-file.h
index 6ed74d1637..f1c8a9df13 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -75,7 +75,7 @@ void free_hashfile(struct hashfile *f);
  * Finalize the hashfile by flushing data to disk and free'ing it.
  */
 int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int);
-void hashwrite(struct hashfile *, const void *, uint32_t);
+void hashwrite(struct hashfile *, const void *, size_t);
 void hashflush(struct hashfile *f);
 void crc32_begin(struct hashfile *);
 uint32_t crc32_end(struct hashfile *);
-- 
2.53.0
Previous: Elia PintoNext: Elia Pinto
Message 2 of 4 in “use size_t for a few sizes that are 32 bits everywhere”
  1. 0/3 use size_t for a few sizes that are 32 bits everywhereElia Pinto, Nov 1, 2026
  2. 1/3 csum-file: use size_t for the count passed to hashwrite()Elia Pinto, Nov 1, 2026
  3. 2/3 diff: use size_t for the size passed to count_lines()Elia Pinto, Nov 1, 2026
  4. 3/3 diffcore-delta: use size_t for the size of the buffer to hashElia Pinto, Nov 1, 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.