git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] history: do not dereference NULL when parent tree is missing

From
Patrick Steinhardt <ps@pks.im>
Date
Sep 3, 2026, 05:26 UTC
Message-ID
<apkFBluOhc3SyKV1@pks.im>
In-Reply-To
<5438d465.ab31e.1a062047bd5.Coremail.zkd18cjb@mail.ustc.edu.cn>
On Wed, Sep 02, 2026 at 08:07:36PM +0800, zkd18cjb@mail.ustc.edu.cn wrote:
Show 7 quoted lines
> 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
> (release build; UBSan reports a null-pointer member access at
> builtin/history.c:789).
Nit: the information in the braces does not really add a lot of signal,
I'd just drop it.
> 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>
Nit: your From address does not match the Signed-off-by.
[snip]
Show 9 quoted lines
> Reproduction (verified on master @ f78ce2f7b6, x86-64 Linux):
> 
>     git init r && cd r
>     git config user.email t@t && git config user.name t
>     echo a > f && git add f && git commit -qm one
>     echo b > f && git commit -qam two
>     tree=$(git rev-parse 'HEAD^^{tree}')
>     rm .git/objects/$(echo "$tree" | cut -c1-2)/$(echo "$tree" | cut -c3-)
>     GIT_EDITOR=true git history split HEAD

We could of course add a test for this, but I don't really think that it's worth it.

Show 12 quoted lines
> 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;
> +	}
Yup, the fix looks obviously good to me, thanks!
Patrick
Previous: zkd18cjb@mail.ustc.edu.cnNext: Jinbao Chen
Message 2 of 4 in “history: do not dereference NULL when parent tree is missing”
  1. history: do not dereference NULL when parent tree is missingzkd18cjb@mail.ustc.edu.cn, Sep 2, 2026
  2. Patrick SteinhardtSep 3, 2026
  3. Jinbao ChenSep 3, 2026
  4. Patrick SteinhardtSep 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.