object-file.c: use size_t for header lengths

Continue walking the code path for the >4GB `hash-object --literally` test. The `hash_object_file_literally()` function internally uses both `hash_object_file()` and `write_object_file_prepare()`. Both function signatures use `unsigned long` rather than `size_t` for the mem buffer sizes. Use `size_t` instead, for LLP64 compatibility. While at it, convert those function's object's header buffer length to `size_t` for consistency. The value is already upcast to `uintmax_t` for print format compatibility. Note: The hash-object test still does not pass. A subsequent commit continues to walk the call tree's lower level hash functions to identify further fixes. Signed-off-by: Philip Oakley <philipoakley@iee.email> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Philip Oakley committed Jun 16, 2026 at 14:49 UTC a39fda4fca37c1b8700ccfe0f9d0194445373b97
6 files changed +13 -13
object-file.c
+5 -5
@@ -318,7 +318,7 @@ int parse_loose_header(const char *hdr, struct object_info *oi)
318 static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c,
319 const void *buf, unsigned long len,
320 struct object_id *oid,
321 - char *hdr, int *hdrlen)
321 + char *hdr, size_t *hdrlen)
322 {
323 algo->init_fn(c);
324 git_hash_update(c, hdr, *hdrlen);
@@ -327,9 +327,9 @@ static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_c
327 }
328
329 void write_object_file_prepare(const struct git_hash_algo *algo,
330 - const void *buf, unsigned long len,
330 + const void *buf, size_t len,
331 enum object_type type, struct object_id *oid,
332 - char *hdr, int *hdrlen)
332 + char *hdr, size_t *hdrlen)
333 {
334 struct git_hash_ctx c;
335
@@ -472,11 +472,11 @@ out:
472 }
473
474 void hash_object_file(const struct git_hash_algo *algo, const void *buf,
475 - unsigned long len, enum object_type type,
475 + size_t len, enum object_type type,
476 struct object_id *oid)
477 {
478 char hdr[MAX_HEADER_LEN];
479 - int hdrlen = sizeof(hdr);
479 + size_t hdrlen = sizeof(hdr);
480
481 write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
482 }
object-file.h
+3 -3
@@ -131,12 +131,12 @@ int finalize_object_file_flags(struct repository *repo,
131 enum finalize_object_file_flags flags);
132
133 void hash_object_file(const struct git_hash_algo *algo, const void *buf,
134 - unsigned long len, enum object_type type,
134 + size_t len, enum object_type type,
135 struct object_id *oid);
136 void write_object_file_prepare(const struct git_hash_algo *algo,
137 - const void *buf, unsigned long len,
137 + const void *buf, size_t len,
138 enum object_type type, struct object_id *oid,
139 - char *hdr, int *hdrlen);
139 + char *hdr, size_t *hdrlen);
140 int write_loose_object(struct odb_source_loose *loose,
141 const struct object_id *oid, char *hdr,
142 int hdrlen, const void *buf, unsigned long len,
odb/source-files.c
+1 -1
@@ -159,7 +159,7 @@ static int odb_source_files_freshen_object(struct odb_source *source,
159 }
160
161 static int odb_source_files_write_object(struct odb_source *source,
162 - const void *buf, unsigned long len,
162 + const void *buf, size_t len,
163 enum object_type type,
164 struct object_id *oid,
165 struct object_id *compat_oid,
odb/source-inmemory.c
+1 -1
@@ -227,7 +227,7 @@ static int odb_source_inmemory_count_objects(struct odb_source *source,
227 }
228
229 static int odb_source_inmemory_write_object(struct odb_source *source,
230 - const void *buf, unsigned long len,
230 + const void *buf, size_t len,
231 enum object_type type,
232 struct object_id *oid,
233 struct object_id *compat_oid UNUSED,
odb/source-loose.c
+2 -2
@@ -591,7 +591,7 @@ static int odb_source_loose_freshen_object(struct odb_source *source,
591 }
592
593 static int odb_source_loose_write_object(struct odb_source *source,
594 - const void *buf, unsigned long len,
594 + const void *buf, size_t len,
595 enum object_type type, struct object_id *oid,
596 struct object_id *compat_oid_in,
597 enum odb_write_object_flags flags)
@@ -601,7 +601,7 @@ static int odb_source_loose_write_object(struct odb_source *source,
601 const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
602 struct object_id compat_oid;
603 char hdr[MAX_HEADER_LEN];
604 - int hdrlen = sizeof(hdr);
604 + size_t hdrlen = sizeof(hdr);
605
606 /* Generate compat_oid */
607 if (compat) {
odb/source.h
+1 -1
@@ -199,7 +199,7 @@ struct odb_source {
199 * return 0 on success, a negative error code otherwise.
200 */
201 int (*write_object)(struct odb_source *source,
202 - const void *buf, unsigned long len,
202 + const void *buf, size_t len,
203 enum object_type type,
204 struct object_id *oid,
205 struct object_id *compat_oid,