All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Wonseok Oh via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,  Wonseok Oh <wonseok_oh@korea.ac.kr>,
	 Wonseok Oh <marinelay7@gmail.com>
Subject: Re: [PATCH] fast-import: catch missing data after inline M at EOF
Date: Sat, 21 Nov 2026 12:03:58 -0800	[thread overview]
Message-ID: <xmqqeccekl3l.fsf@gitster.g> (raw)
In-Reply-To: <pull.2323.git.1795246845186.gitgitgadget@gmail.com> (Wonseok Oh via GitGitGadget's message of "Sat, 21 Nov 2026 07:40:45 +0000")

"Wonseok Oh via GitGitGadget" <gitgitgadget@gmail.com> writes:

> If `M <mode> inline <path>` appears at the end of input,
> file_change_m() exits its read loop on EOF without reading a `data`
> command. It then puts an uninitialized stack object ID into the tree
> and exits 0, leaving a tree entry for a missing blob that `git fsck`
> flags.
>
> note_change_n() avoids this by calling parse_and_store_blob() at EOF,
> which dies on the missing `data` command. Do the same in
> file_change_m(), and add a test.

This reasoning seems wrong.  The reason note_change_n() can afford
to call parse_and_store_blob() is because it does not loop.  This
codepath needs a separate solution, I am afraid.

> diff --git a/builtin/fast-import.c b/builtin/fast-import.c
> index ab5d2a2344..2b271222e1 100644
> --- a/builtin/fast-import.c
> +++ b/builtin/fast-import.c
> @@ -2456,8 +2456,9 @@ static void file_change_m(struct fast_import_state *state,
>  		if (S_ISDIR(mode))
>  			die(_("directories cannot be specified 'inline': %s"),
>  				command_buf.buf);
> -		while (read_next_command(state) != EOF) {
> +		for (;;) {
>  			const char *v;
> +			read_next_command(state);
>  			if (skip_prefix(command_buf.buf, "cat-blob ", &v))
>  				parse_cat_blob(state, v);
>  			else {

Imagine that "cat-blob <object name>" appears on an incomplete line
without a trailing LF at the end of the stream.  The updated code
ignores the return value of read_next_command(), which would make us
loop forever here, I suspect.

 * We are about to read the final line "cat-blob <object name>".
   read_next_command() calls strbuf_getline_lf(), which returns 0
   (which is assigned to stdin_eof), stuffs the incomplete line in
   command_buf.buf and returns.  We have "cat-blob <object name>"
   in the command_buf (without the terminating LF).

 * We call skip_prefix() and call parse_cat_blob().  It does its
   thing, but does not do anything to affect this loop.

 * The loop calls read_next_command() again.  strbuf_getline_lf() is
   called, because stdin_eof in read_next_command() is still 0.  It
   notices that the underlying stdin stream has already given EOF,
   and returns EOF.  read_next_command() reacts to this EOF, sets
   stdin_eof = EOF, and returns EOF.

 * You updated the code to ignore this EOF.  In the meantime, nobody
   touched command_buf in the previous step.  We call skip_prefix()
   and call parse_cat_blob() with the same "cat-blob <object name>"
   that lacks the terminating newline.

 * The loop calls read_next_command() again.  strbuf_getline_lf() is
   not even called and we get EOF back.  Again you ignore it and we
   do the parse_cat_blob() dance once again.  Nobody will get us out
   of this loop.

In short, you have to pay attention to what read_next_command()
returns, even if that does not mean you have to leave the function
immediately, I think.

  reply	other threads:[~2026-11-21 20:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21  7:40 [PATCH] fast-import: catch missing data after inline M at EOF Wonseok Oh via GitGitGadget
2026-11-21 20:03 ` Junio C Hamano [this message]
     [not found]   ` <CAD2pp5sCB8kj6243g63X+Msg=cFR4ODYto5OUA3rYrnioVxShQ@mail.gmail.com>
2026-11-22  4:01     ` Wonseok Oh
2026-11-24  5:12 ` [PATCH v2] fast-import: die on EOF after an inline M command Wonseok Oh via GitGitGadget
2026-11-24 18:12   ` Junio C Hamano
2026-11-25  1:46     ` Wonseok Oh

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=xmqqeccekl3l.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=marinelay7@gmail.com \
    --cc=wonseok_oh@korea.ac.kr \
    /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.