From 76621488e867bab3a8319098f09a395aea2a8b4a Mon Sep 17 00:00:00 2001 From: Jinbao Chen Date: Thu, 3 Sep 2026 14:36:57 +0800 Subject: [PATCH] history: do not dereference NULL when parent tree is missing 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 Acked-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- builtin/history.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builtin/history.c b/builtin/history.c index 091465a59e..3bc72fc8c4 100644 --- a/builtin/history.c +++ b/builtin/history.c @@ -755,6 +755,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)) {