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

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
Previous: Elia PintoNext: Elia Pinto
Message 10 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.