From: Patrick Steinhardt <ps@pks.im>
To: zkd18cjb@mail.ustc.edu.cn
Cc: git@vger.kernel.org, gitster@pobox.com, toon@iotcl.com
Subject: Re: [PATCH] history: do not dereference NULL when parent tree is missing
Date: Thu, 3 Sep 2026 07:26:30 +0200 [thread overview]
Message-ID: <apkFBluOhc3SyKV1@pks.im> (raw)
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:
> 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]
> 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.
> 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
next prev parent reply other threads:[~2026-09-03 5:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 12:07 [PATCH] history: do not dereference NULL when parent tree is missing zkd18cjb
2026-09-03 5:26 ` Patrick Steinhardt [this message]
2026-09-03 6:36 ` [PATCH v2] " Jinbao Chen
2026-09-03 7:52 ` Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=apkFBluOhc3SyKV1@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=toon@iotcl.com \
--cc=zkd18cjb@mail.ustc.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.