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

[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
Previous: Elia PintoNext: Elia Pinto
Message 5 of 13 in “use size_t when receiving and verifying packs”
  1. 0/4 use size_t when receiving and verifying packsElia Pinto, Oct 31, 2026
  2. 1/4 unpack-objects: use size_t for object sizesElia Pinto, Oct 31, 2026
  3. 2/4 index-pack: use size_t in write_compressed()Elia Pinto, Oct 31, 2026
  4. 3/4 index-pack: use size_t for object sizesElia Pinto, Oct 31, 2026
  5. 4/4 pack-check: use size_t for the size passed to verify callbacksElia Pinto, Oct 31, 2026
  6. 0/4 use size_t when receiving and verifying packsElia Pinto, Nov 18, 2026
  7. 1/4 unpack-objects: use size_t for object sizesElia Pinto, Nov 18, 2026
  8. Patrick SteinhardtNov 18, 2026
  9. 2/4 index-pack: use size_t in write_compressed()Elia Pinto, Nov 18, 2026
  10. Patrick SteinhardtNov 18, 2026
  11. 3/4 index-pack: use size_t for object sizesElia Pinto, Nov 18, 2026
  12. 4/4 pack-check: use size_t for the size passed to verify callbacksElia Pinto, Nov 18, 2026
  13. Patrick SteinhardtNov 18, 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.