[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