From: "Wonseok Oh via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Wonseok Oh <wonseok_oh@korea.ac.kr>, Wonseok Oh <marinelay7@gmail.com>
Subject: [PATCH] fast-import: catch missing data after inline M at EOF
Date: Sat, 21 Nov 2026 07:40:45 +0000 [thread overview]
Message-ID: <pull.2323.git.1795246845186.gitgitgadget@gmail.com> (raw)
From: Wonseok Oh <marinelay7@gmail.com>
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.
Signed-off-by: Wonseok Oh <marinelay7@gmail.com>
---
fast-import: catch missing data after inline M at EOF
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2323%2Fmarinelay%2Ffast-import-inline-eof-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2323/marinelay/fast-import-inline-eof-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2323
builtin/fast-import.c | 3 ++-
t/t9300-fast-import.sh | 16 ++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
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 {
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 15f511fb6b..c291b0cf70 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -745,6 +745,22 @@ test_expect_success 'D: verify file6' '
test_cmp expect actual
'
+test_expect_success 'D: fail on inline data cut off at end of input' '
+ cat >input <<-INPUT_END &&
+ commit refs/heads/D-inline-eof
+ committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+ data <<COMMIT
+ inline data cut off
+ COMMIT
+
+ M 644 inline file
+ INPUT_END
+
+ test_must_fail git fast-import <input 2>err &&
+ test_grep "expected ${SQ}data n${SQ} command" err &&
+ test_must_fail git rev-parse --verify -q refs/heads/D-inline-eof
+'
+
###
### series E
###
base-commit: f7de81456940dd6f3274e461149bba12965de609
--
gitgitgadget
reply other threads:[~2026-11-21 7:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=pull.2323.git.1795246845186.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox