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>
Subject: Re: [PATCH v2 3/5] odb/source-loose: check object size when streaming loose objects
Date: Tue, 17 Nov 2026 14:55:46 -0800 [thread overview]
Message-ID: <xmqqse0zawzx.fsf@gitster.g> (raw)
In-Reply-To: <a8572aa836bcc17a7442ff92abd934155e7f6c74.1794914210.git.gitter.spiros@gmail.com> (Elia Pinto's message of "Tue, 17 Nov 2026 12:38:56 +0100")
Elia Pinto <gitter.spiros@gmail.com> writes:
> if (status == Z_STREAM_END) {
> git_inflate_end(&st->z);
> + /*
> + * The object must be exactly as large as its
> + * header claims.
> + */
> + if (st->total_read + total_read != st->base.size) {
> + error(_("corrupt loose object '%s'"),
> + oid_to_hex(&st->oid));
> + st->z_state = ODB_LOOSE_READ_STREAM_ERROR;
> + return -1;
> + }
Hmph, is this unconditionally noisy error() warranted? The other,
existing failure mode in this function below this "if" block, whose
"return -1" is visible as precontext for the next hunk, is a silent
error return. Yet, you are trying to set an appropriate error code
in st->z_state, which presumably is so that the caller can react to
it and give an appropriate error message up there, not down here,
no?
It feels very inconsistent. Either the existing silent "return -1"
we see below should also become noisy, or we make sure that some
caller up in the callchain reacts to st->z_state to report an error,
keeping this new code just as silent. My preference is the latter.
> st->z_state = ODB_LOOSE_READ_STREAM_DONE;
> break;
> }
> @@ -335,6 +347,7 @@ static ssize_t read_istream_loose(struct odb_stream *_st, char *buf, size_t sz)
> return -1;
> }
> }
> + st->total_read += total_read;
> return total_read;
> }
>
> @@ -388,6 +401,7 @@ static int odb_source_loose_read_object_stream(struct odb_stream **out,
>
> st->mapped = mapped;
> st->mapsize = mapsize;
> + oidcpy(&st->oid, oid);
And if we do choose to make the low-level helper silent (and return
error code via st->z_state), we do not need to add this oid member
to the structure or pay the overhead to memcpy here.
Thanks.
> diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
> index f2b24dd278..622d734ad3 100755
> --- a/t/t1006-cat-file.sh
> +++ b/t/t1006-cat-file.sh
> @@ -1513,4 +1513,22 @@ test_expect_success PIPE 'concurrently written alternates are loaded' '
> )
> '
>
> +test_expect_success 'setup blobs with bogus size in header' '
> + git init bogus-size &&
> + echo_without_newline short |
> + loose_obj bogus-size/.git/objects blob 100 >oid-too-big &&
> + echo_without_newline "much longer" |
> + loose_obj bogus-size/.git/objects blob 3 >oid-too-small
> +'
> +
> +test_expect_success 'streaming blob shorter than its header fails' '
> + test_must_fail git -C bogus-size cat-file blob $(cat oid-too-big) >out 2>err &&
> + test_grep "corrupt loose object" err
> +'
> +
> +test_expect_success 'streaming blob longer than its header fails' '
> + test_must_fail git -C bogus-size cat-file blob $(cat oid-too-small) >out 2>err &&
> + test_grep "corrupt loose object" err
> +'
> +
> test_done
next prev parent reply other threads:[~2026-11-17 22:55 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
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 [this message]
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=xmqqse0zawzx.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitter.spiros@gmail.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.