All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Elia Pinto <gitter.spiros@gmail.com>
Cc: git@vger.kernel.org,
	 Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Patrick Steinhardt <ps@pks.im>,
	 Jonathan Tan <jonathantanmy@fastmail.com>
Subject: Re: [PATCH v2 2/5] object-file: use size_t for loose object sizes
Date: Tue, 17 Nov 2026 14:34:46 -0800	[thread overview]
Message-ID: <xmqqzev7axyx.fsf@gitster.g> (raw)
In-Reply-To: <eca5d3ddb88e03ae647a66d861a4c89a4c490fd7.1794914210.git.gitter.spiros@gmail.com> (Elia Pinto's message of "Tue, 17 Nov 2026 12:38:55 +0100")

Elia Pinto <gitter.spiros@gmail.com> writes:

> Since c6a4629e32 (odb: use size_t for object_info.sizep and the size
> APIs, 2026-06-15), parse_loose_header() reports the object size as a
> size_t, but unpack_loose_rest() still takes it as an "unsigned long".
> On 64-bit Windows, where "long" has 32 bits while size_t has 64, the
> size is truncated on the way. A header claiming 4GiB + 5 bytes thus
> makes us allocate a 6-byte buffer, the size check added by the
> previous commit is happy because the stream really has 5 bytes, and
> the caller gets that buffer back together with *oi->sizep set to
> 4GiB + 5. Any user of the object then reads far beyond the end of the
> buffer; read_loose_object() already does so when it hashes the
> contents.
>
> Use size_t for the size in unpack_loose_rest() and check_stream_oid(),
> and while at it for the size of the mapped file in map_fd(),
> odb_source_loose_map_object() and unpack_loose_header(), so that the
> whole loose object reading path agrees on the type.

Makes sense.  And the changes are straightforward.

Move from ulong to size_t would help truncation on platforms with
32-bit ulong and 64-bit size_t, but does not addres any unsigned
arithmetic wrapping around.  Are there places where we should
be using st_add() family of functions?

Thanks.

  reply	other threads:[~2026-11-17 22:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 10:28 [PATCH 0/6] loose object size checks and a few size truncations Elia Pinto
2026-10-30 10:28 ` [PATCH 1/6] object-file: check size of inflated loose object against its header Elia Pinto
2026-10-30 10:28 ` [PATCH 2/6] object-file: use size_t for loose object sizes Elia Pinto
2026-10-30 10:28 ` [PATCH 3/6] odb/source-loose: check object size when streaming loose objects Elia Pinto
2026-10-30 10:28 ` [PATCH 4/6] cat-file: use size_t for the length passed to batch_write() Elia Pinto
2026-10-30 10:28 ` [PATCH 5/6] notes: avoid truncating the size of concatenated notes Elia Pinto
2026-10-30 10:28 ` [PATCH 6/6] diff: use size_t in count_trailing_blank() Elia Pinto
2026-11-17 11:38 ` [PATCH v2 0/5] loose object size checks and a few size truncations Elia Pinto
2026-11-17 11:38   ` [PATCH v2 1/5] object-file: check size of inflated loose object against its header Elia Pinto
2026-11-17 19:33     ` Junio C Hamano
2026-11-17 11:38   ` [PATCH v2 2/5] object-file: use size_t for loose object sizes Elia Pinto
2026-11-17 22:34     ` Junio C Hamano [this message]
2026-11-17 11:38   ` [PATCH v2 3/5] odb/source-loose: check object size when streaming loose objects Elia Pinto
2026-11-17 22:55     ` Junio C Hamano
2026-11-17 11:38   ` [PATCH v2 4/5] cat-file: use size_t for the length passed to batch_write() Elia Pinto
2026-11-17 22:59     ` Junio C Hamano
2026-11-17 11:38   ` [PATCH v2 5/5] notes: avoid truncating the size of concatenated notes Elia Pinto
2026-11-17 23:01     ` Junio C Hamano

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=xmqqzev7axyx.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitter.spiros@gmail.com \
    --cc=jonathantanmy@fastmail.com \
    --cc=ps@pks.im \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.