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

[PATCH 2/4] index-pack: use size_t in write_compressed()

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Oct 31, 2026, 11:39 UTC
Message-ID
<438f7c6ba2ed76a782b8af6f5bc1edab1f3fb73f.1793446357.git.gitter.spiros@gmail.com>
In-Reply-To
<cover.1793446357.git.gitter.spiros@gmail.com>

write_compressed() in builtin/index-pack.c takes the object size as an "unsigned int" and returns an "int", which are 32 bits wide on all platforms. It is used by append_obj_to_pack() when resolving thin packs with --fix-thin.

With a local base of 4GiB or more, write_compressed() compresses only the first "size mod 2^32" bytes, while the pack header written by append_obj_to_pack() records the full size. Later, when resolving deltas against that base, unpack_data() encounters an early end of stream and dies with "serious inflate inconsistency". Shrinking the parameter to 16 bits and using a 100KiB base makes "git index-pack --fix-thin" die the same way.

Use size_t for both the size parameter and the return value.

Triggering this requires processing a local base of 4GiB or more, so no test is added.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 builtin/index-pack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 0264c18c5f..f65228468b 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1411,7 +1411,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
 		    nr_ofs_deltas + nr_ref_deltas - nr_resolved_deltas);
 }
 
-static int write_compressed(struct hashfile *f, void *in, unsigned int size)
+static size_t write_compressed(struct hashfile *f, void *in, size_t size)
 {
 	git_zstream stream;
 	int status;
-- 
2.53.0
Previous: Elia PintoNext: Elia Pinto
Message 3 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.