From 1736db5ae966445f9f4ab66486c988dddb8ff9a9 Mon Sep 17 00:00:00 2001 From: Wonseok Oh Date: Sat, 21 Nov 2026 07:27:37 +0000 Subject: [PATCH] fast-import: die on EOF after an inline M command After "M inline ", fast-import expects a "data" command. If the input ends there, file_change_m() leaves its read loop without reading any data and writes an uninitialized object ID into the tree. fast-import then exits 0, and "git fsck" reports a missing blob. Die when read_next_command() returns EOF in that loop, just as parse_data() already dies on any command other than "data". Signed-off-by: Wonseok Oh --- builtin/fast-import.c | 4 +++- t/t9300-fast-import.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index ab5d2a23448c72..0a0f5a91a5468d 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -2456,8 +2456,10 @@ 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; + if (read_next_command(state) == EOF) + die(_("expected 'data n' command, found end of input")); 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 15f511fb6b29e0..29da93be1dea59 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -745,6 +745,40 @@ 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 <err && + test_grep "expected ${SQ}data n${SQ} command" err && + test_must_fail git rev-parse --verify -q refs/heads/D-inline-eof +' + +test_expect_success 'D: fail on unterminated cat-blob after inline M at end of input' ' + blob=$(echo hello | git hash-object -w --stdin) && + cat >input <<-INPUT_END && + commit refs/heads/D-inline-cat-blob-eof + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <>input && + + test_must_fail git fast-import out 2>err && + test_grep "expected ${SQ}data n${SQ} command" err && + test_must_fail git rev-parse --verify -q refs/heads/D-inline-cat-blob-eof +' + ### ### series E ###