From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: "Elia Pinto" <gitter.spiros@gmail.com>,
git@vger.kernel.org,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Jeff King" <peff@peff.net>
Subject: Re: [PATCH v2 1/5] object-file: check size of inflated loose object against its header
Date: Wed, 18 Nov 2026 10:17:54 -0800 [thread overview]
Message-ID: <xmqqbj7m6m25.fsf@gitster.g> (raw)
In-Reply-To: <av2YSgkd2fUNRlNM@pks.im> (Patrick Steinhardt's message of "Wed, 18 Nov 2026 13:21:30 +0100")
Patrick Steinhardt <ps@pks.im> writes:
> On Tue, Nov 17, 2026 at 12:38:54PM +0100, Elia Pinto wrote:
>> unpack_loose_rest() allocates a buffer of the size given in the object
>> header and inflates the rest of the stream into it, but it never checks
>> that the stream actually produced that many bytes. If the compressed
>> data ends early we return success with the tail of the buffer never
>> written, and callers like odb_read_object() hand it out as object
>> content. For example, "git cat-file commit" on a loose object whose
>> header says "commit 200" but which contains only 44 bytes prints 156
>> bytes of uninitialized heap memory.
>
> That's certainly fishy.
>
>> The opposite case slips through, too: when the whole object fits into
>> the buffer filled by unpack_loose_header(), we copy only "size" bytes
>> out of it, the stream has already ended, and the extra data is silently
>> dropped.
>
> Hum, this part I don't quite understand. Do you mean to say that the
> header declares "commit 200", but it actually carries 400 bytes, so we
> only copy the first 200 and ignore the remainder? If so, why would the
> stream have already ended in that case?
The opposite case is that the initial inflation into 32-byte buffer
is sufficient to unpack both the header and the payload. See my
walkthru in https://lore.kernel.org/git/xmqqbj7ndzi7.fsf@gitster.g/
and other points you mention in this message would hopefully become
clearer.
Thanks.
next prev parent reply other threads:[~2026-11-18 18:17 UTC|newest]
Thread overview: 20+ 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-18 12:21 ` Patrick Steinhardt
2026-11-18 18:17 ` Junio C Hamano [this message]
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
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=xmqqbj7m6m25.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitter.spiros@gmail.com \
--cc=peff@peff.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox