Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Elia Pinto <gitter.spiros@gmail.com>
Cc: git@vger.kernel.org,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v2 2/4] index-pack: use size_t in write_compressed()
Date: Wed, 18 Nov 2026 14:33:45 +0100	[thread overview]
Message-ID: <av2pOWbYxNDYvS9p@pks.im> (raw)
In-Reply-To: <9952f0fb104450461661b3f8b5f646760198744c.1794984184.git.gitter.spiros@gmail.com>

On Wed, Nov 18, 2026 at 07:56:36AM +0100, Elia Pinto wrote:
> 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

  reply	other threads:[~2026-11-18 13:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 11:39 [PATCH 0/4] use size_t when receiving and verifying packs Elia Pinto
2026-10-31 11:39 ` [PATCH 1/4] unpack-objects: use size_t for object sizes Elia Pinto
2026-10-31 11:39 ` [PATCH 2/4] index-pack: use size_t in write_compressed() Elia Pinto
2026-10-31 11:39 ` [PATCH 3/4] index-pack: use size_t for object sizes Elia Pinto
2026-10-31 11:39 ` [PATCH 4/4] pack-check: use size_t for the size passed to verify callbacks Elia Pinto
2026-11-18  6:56 ` [PATCH v2 0/4] use size_t when receiving and verifying packs Elia Pinto
2026-11-18  6:56   ` [PATCH v2 1/4] unpack-objects: use size_t for object sizes Elia Pinto
2026-11-18 13:33     ` Patrick Steinhardt
2026-11-18  6:56   ` [PATCH v2 2/4] index-pack: use size_t in write_compressed() Elia Pinto
2026-11-18 13:33     ` Patrick Steinhardt [this message]
2026-11-18  6:56   ` [PATCH v2 3/4] index-pack: use size_t for object sizes Elia Pinto
2026-11-18  6:56   ` [PATCH v2 4/4] pack-check: use size_t for the size passed to verify callbacks Elia Pinto
2026-11-18 13:34     ` Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=av2pOWbYxNDYvS9p@pks.im \
    --to=ps@pks.im \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=gitter.spiros@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox