Commit

76621488e867bab3a8319098f09a395aea2a8b4a

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 <zkd18cjb@mail.ustc.edu.cn>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jinbao Chen <zkd18cjb@mail.ustc.edu.cn> · 2026-09-03 06:36 UTC · committed by Junio C Hamano

Browse files
1 file changed, +4 −0
modified builtin/history.c
@@ -755,6 +755,10 @@ static int write_ondisk_index(struct repository *repo,
755 755 opts.dst_index = &index;
756 756
757 757 tree = repo_parse_tree_indirect(repo, oid);
758 + if (!tree) {
759 + ret = error(_("unable to parse tree %s"), oid_to_hex(oid));
760 + goto out;
761 + }
758 762 init_tree_desc(&tree_desc, &tree->object.oid, tree->buffer, tree->size);
759 763
760 764 if (unpack_trees(1, &tree_desc, &opts)) {