Re: [PATCH v2 2/4] index-pack: use size_t in write_compressed()
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Nov 18, 2026, 13:33 UTC
- Message-ID
- <av2pOWbYxNDYvS9p@pks.im>
- In-Reply-To
- <9952f0fb104450461661b3f8b5f646760198744c.1794984184.git.gitter.spiros@gmail.com>
On Wed, Nov 18, 2026 at 07:56:36AM +0100, Elia Pinto wrote:
Show 14 quoted lines
> 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.
Hmm. It's probably an improvement, but the only caller does this:
obj[1].idx.offset += write_compressed(f, buf, size);
That's a `struct pack_idx_entry`, but its `offset` field is of type `off_t`, which is signed. It feels sufficiently unlikely to ever overflow, but should we verify regardless that we don't?
> Triggering this requires processing a local base of 4GiB or more, so > no test is added.
Not even an EXPENSIVE one?
Patrick