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

[PATCH 1/4] object-file: use size_t in check_object_signature()

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Oct 31, 2026, 11:09 UTC
Message-ID
<1f1d1dab569f2d8ad3087d8c877a87747e0b0c6a.1793444420.git.gitter.spiros@gmail.com>
In-Reply-To
<cover.1793444420.git.gitter.spiros@gmail.com>

check_object_signature() takes the object size as an "unsigned long", while its callers pass a size_t from odb_read_object(), and the internal function it calls, hash_object_file(), already accepts a size_t. So the size is narrowed only here, and specifically on Windows where "long" is 32 bits wide.

On platforms with 32-bit longs, hashing an object of 4GiB or more truncates the size, causing it to hash only a prefix. This mismatch results in valid objects being incorrectly flagged as corrupt by callers like parse_object() or git fsck.

Use size_t for the size parameter, matching what callers already provide.

Triggering this requires processing 4GiB or more of input on a platform where "long" is 32 bits, so no test is added.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 object-file.c | 2 +-
 object-file.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/object-file.c b/object-file.c
index c049bf13f7..3cb8f3fac1 100644
--- a/object-file.c
+++ b/object-file.c
@@ -111,7 +111,7 @@ int format_object_header(char *str, size_t size, enum object_type type,
 }
 
 int check_object_signature(struct repository *r, const struct object_id *oid,
-			   void *buf, unsigned long size,
+			   void *buf, size_t size,
 			   enum object_type type)
 {
 	const struct git_hash_algo *algo =
diff --git a/object-file.h b/object-file.h
index f44758c4f8..53c0e6df09 100644
--- a/object-file.h
+++ b/object-file.h
@@ -92,7 +92,7 @@ int format_object_header(char *str, size_t size, enum object_type type,
  * what we expected, but it might also indicate another error.
  */
 int check_object_signature(struct repository *r, const struct object_id *oid,
-			   void *map, unsigned long size,
+			   void *map, size_t size,
 			   enum object_type type);
 
 /**
-- 
2.53.0
Previous: Elia PintoNext: Elia Pinto
Message 2 of 7 in “use size_t when parsing and checking objects”
  1. 0/4 use size_t when parsing and checking objectsElia Pinto, Oct 31, 2026
  2. 1/4 object-file: use size_t in check_object_signature()Elia Pinto, Oct 31, 2026
  3. 2/4 fsck: use size_t for the size of objects to checkElia Pinto, Oct 31, 2026
  4. 3/4 object, commit, tag: use size_t when parsing object buffersElia Pinto, Oct 31, 2026
  5. 4/4 tag, fmt-merge-msg, ref-filter: use size_t for message buffersElia Pinto, Oct 31, 2026
  6. Simon RichterOct 31, 2026
  7. Elia PintoOct 31, 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.