Re: [PATCH v2] history: do not dereference NULL when parent tree is missing
- From
- Jinbao Chen <zkd18cjb@mail.ustc.edu.cn>
- Date
- Sep 3, 2026, 06:36 UTC
- Message-ID
- <20260903063657.2067303-1-zkd18cjb@mail.ustc.edu.cn>
- In-Reply-To
- <5438d465.ab31e.1a062047bd5.Coremail.zkd18cjb@mail.ustc.edu.cn>
write_ondisk_index() dereferences the return value of repo_parse_tree_indirect() unconditionally. If the parent commit's tree object is missing from the object store (corrupt repository, object removed by tooling, or incomplete restore), the function returns NULL and "git history split" crashes with a SIGSEGV.
Guard the parse result and error out gracefully, following the codebase convention for objects that cannot be loaded.
Signed-off-by: Jinbao Chen <zkd18cjb@mail.ustc.edu.cn> --- Thanks for the review!
Changes since v1 (no functional changes): - Dropped the parenthetical note about the UBSan diagnostic from the commit message, as suggested. - Sent with the From address matching the Signed-off-by.
builtin/history.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/builtin/history.c b/builtin/history.c index 000155ad9c..097631f5ba 100644 --- a/builtin/history.c +++ b/builtin/history.c @@ -786,6 +786,10 @@ static int write_ondisk_index(struct repository *repo, opts.dst_index = &index; tree = repo_parse_tree_indirect(repo, oid); + if (!tree) { + ret = error(_("unable to parse tree %s"), oid_to_hex(oid)); + goto out; + } init_tree_desc(&tree_desc, &tree->object.oid, tree->buffer, tree->size); if (unpack_trees(1, &tree_desc, &opts)) {
-- 2.53.0