[PATCH 4/4] pack-check: use size_t for the size passed to verify callbacks
- From
Elia Pinto <gitter.spiros@gmail.com>
- Date
- Oct 31, 2026, 11:39 UTC
- Message-ID
- <87b0d2bd96ad2e62f770c556eca9589bf7aad11c.1793446357.git.gitter.spiros@gmail.com>
- In-Reply-To
- <cover.1793446357.git.gitter.spiros@gmail.com>
verify_pack() in pack-check.c passes each object to a verify_fn callback (defined in pack.h) taking the object size as an "unsigned long", even though pack-check already handles it as a size_t. This signature is also replicated in struct odb_fsck_options (odb.h) and implemented by fsck_obj_buffer() in builtin/fsck.c.
On platforms where "long" is 32 bits, running "git fsck" on packs with objects of 4GiB or more passes a truncated size to fsck_obj_buffer(), causing parse_object_buffer() and fsck_object() to inspect only a prefix.
Use size_t for the size parameter in verify_fn, struct odb_fsck_options.object_cb, and fsck_obj_buffer().
Triggering this requires processing objects of 4GiB or more on a platform where "long" is 32 bits, so no test is added.
Signed-off-by: Elia Pinto <gitter.spiros@gmail.com> --- builtin/fsck.c | 2 +- odb.h | 2 +- pack.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c index da90cf84bf..9f62aa1f4e 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -390,7 +390,7 @@ static void check_connectivity(struct repository *repo) } static int fsck_obj_buffer(const struct object_id *oid, enum object_type type, - unsigned long size, void *buffer, int *eaten, void *cb_data) + size_t size, void *buffer, int *eaten, void *cb_data) { struct repository *repo = cb_data; struct object *obj; diff --git a/odb.h b/odb.h index dd85b880a7..9cb36ed5ad 100644 --- a/odb.h +++ b/odb.h @@ -197,7 +197,7 @@ struct odb_fsck_options { enum odb_fsck_flags flags; int (*object_cb)(const struct object_id *oid, enum object_type type, - unsigned long size, void *buffer, int *eaten, void *cb_data); + size_t size, void *buffer, int *eaten, void *cb_data); void *object_payload; }; diff --git a/pack.h b/pack.h index ada506b5c5..d9649c6ee0 100644 --- a/pack.h +++ b/pack.h @@ -88,7 +88,7 @@ struct progress; /* Note, the data argument could be NULL if object type is blob */ typedef int (*verify_fn)(const struct object_id *oid, enum object_type type, - unsigned long size, + size_t size, void *buffer, int *eaten, void *fn_data);
-- 2.53.0