[PATCH v2 2/4] index-pack: use size_t in write_compressed()
- From
Elia Pinto <gitter.spiros@gmail.com>
- Date
- Nov 18, 2026, 06:56 UTC
- Message-ID
- <9952f0fb104450461661b3f8b5f646760198744c.1794984184.git.gitter.spiros@gmail.com>
- In-Reply-To
- <cover.1794984184.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