{"thread":{"id":"66903","subject":"[PATCH] fast-import: catch missing data after inline M at EOF","startedAt":"2026-11-21T07:40:45Z","lastAt":"2026-11-21T07:40:45Z","messageCount":1,"participants":["Wonseok Oh via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"559021","messageId":"pull.2323.git.1795246845186.gitgitgadget@gmail.com","threadId":"66903","inReplyTo":null,"subject":"[PATCH] fast-import: catch missing data after inline M at EOF","fromName":"Wonseok Oh via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-21T07:40:45Z","receivedAt":"2026-11-21T07:40:45Z","isPatch":true,"sender":{"key":"name:Wonseok Oh","avatar":null},"body":"From: Wonseok Oh <marinelay7@gmail.com>\n\nIf `M <mode> inline <path>` appears at the end of input,\nfile_change_m() exits its read loop on EOF without reading a `data`\ncommand. It then puts an uninitialized stack object ID into the tree\nand exits 0, leaving a tree entry for a missing blob that `git fsck`\nflags.\n\nnote_change_n() avoids this by calling parse_and_store_blob() at EOF,\nwhich dies on the missing `data` command. Do the same in\nfile_change_m(), and add a test.\n\nSigned-off-by: Wonseok Oh <marinelay7@gmail.com>\n---\n    fast-import: catch missing data after inline M at EOF\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2323%2Fmarinelay%2Ffast-import-inline-eof-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2323/marinelay/fast-import-inline-eof-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2323\n\n builtin/fast-import.c  |  3 ++-\n t/t9300-fast-import.sh | 16 ++++++++++++++++\n 2 files changed, 18 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex ab5d2a2344..2b271222e1 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -2456,8 +2456,9 @@ static void file_change_m(struct fast_import_state *state,\n \t\tif (S_ISDIR(mode))\n \t\t\tdie(_(\"directories cannot be specified 'inline': %s\"),\n \t\t\t\tcommand_buf.buf);\n-\t\twhile (read_next_command(state) != EOF) {\n+\t\tfor (;;) {\n \t\t\tconst char *v;\n+\t\t\tread_next_command(state);\n \t\t\tif (skip_prefix(command_buf.buf, \"cat-blob \", &v))\n \t\t\t\tparse_cat_blob(state, v);\n \t\t\telse {\ndiff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\nindex 15f511fb6b..c291b0cf70 100755\n--- a/t/t9300-fast-import.sh\n+++ b/t/t9300-fast-import.sh\n@@ -745,6 +745,22 @@ test_expect_success 'D: verify file6' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'D: fail on inline data cut off at end of input' '\n+\tcat >input <<-INPUT_END &&\n+\tcommit refs/heads/D-inline-eof\n+\tcommitter $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE\n+\tdata <<COMMIT\n+\tinline data cut off\n+\tCOMMIT\n+\n+\tM 644 inline file\n+\tINPUT_END\n+\n+\ttest_must_fail git fast-import <input 2>err &&\n+\ttest_grep \"expected ${SQ}data n${SQ} command\" err &&\n+\ttest_must_fail git rev-parse --verify -q refs/heads/D-inline-eof\n+'\n+\n ###\n ### series E\n ###\n\nbase-commit: f7de81456940dd6f3274e461149bba12965de609\n-- \ngitgitgadget\n\n"}]}