git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Derrick Stolee <derrickstolee@github.com>
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
	"Emily Noneman" <emily.noneman@gmail.com>,
	"Paul Horn" <git@knutwalker.engineer>
Subject: Re: [PATCH] revision.c: set-up "index_state.repo", don't segfault in pack-objects
Date: Fri, 5 Aug 2022 11:25:40 -0400	[thread overview]
Message-ID: <Yu02dOo4G8sy8tI6@coredump.intra.peff.net> (raw)
In-Reply-To: <b6299f8a-f75a-0e96-a6a6-55a7280584bf@github.com>

On Fri, Aug 05, 2022 at 10:48:43AM -0400, Derrick Stolee wrote:

> On 8/5/2022 10:24 AM, Ævar Arnfjörð Bjarmason wrote:
> > Narrowly fix a segfault that's been reported against pack-objects at
> > [1] and [2].
> > 
> > This fixes a segfault in "git pack-objects", see a reports at [1] and
> > [2]. In that case we'd go through the add_index_objects_to_pending()
> > codepath being modified here, and eventually call into
> > new_untracked_cache().
> > 
> > We'd then segfault in new_untracked_cache_flags() as we tried to use a
> > NULL "repo" extracted from the "struct index_state".
> 
> >  		struct worktree *wt = *p;
> > -		struct index_state istate = { NULL };
> > +		struct index_state istate = { .repo = revs->repo };
>   
> Thanks for the fix. It is definitely narrow to this particular
> stack trace.
> 
> It is rare that we create an index that is not 'the_index' in
> this way. However, there are similar { NULL } initializers that
> could be cleaned up in these files:
> 
>  * apply.c
>  * merge-recursive.c
>  * builtin/stash.c
>  * builtin/worktree.c
> 
> Of course, delay these for a follow-up since these uses are
> not causing segfaults in the wild.

We did have another similar segfault recently:

  https://lore.kernel.org/git/YtrdPguYs3a3xekv@kitenet.net/

It's not quite the same case, but I think there's some overlap, and the
reason Ævar couldn't reproduce is that Martin's patch in that thread has
already fixed this case, too.

Using git v2.37.1, I can get a segfault with a backtrace similar to
Emily's by running:

  git init repo
  cd repo
  git commit --allow-empty -m base

  git config core.untrackedCache true
  git worktree add at
  rm .git/worktrees/wt/index

  git gc

And applying the patch from this thread does make it go away. But
likewise for cherry-picking 4447d4129d (read-cache: make `do_read_index()`
always set up `istate->repo`, 2022-07-22), which is already in "master".

Of the two patches, I think 4447d4129d is the better approach. The
assumption in the code seems to be that do_read_index() (and thus
read_index_from(), etc) will set up istate->repo. That patch fixes a
corner case where we failed to do so. And with that fix, there's no need
for the callers to set things up ahead of time. So it covers all of
those initializers you mentioned.

Emily, Paul: I'm 99% sure this will be the case given my reproduction
above, but if you could try reproducing the problem with the current tip
of "master" from git.git, that would confirm the findings.

-Peff

  reply	other threads:[~2022-08-05 15:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12  8:51 Bugreport: pack-objects died of signal 11 Paul Horn
2022-07-14 21:37 ` Jeff King
2022-08-04 18:21   ` Emily Noneman
2022-08-04 20:14     ` Derrick Stolee
2022-08-04 21:07       ` Ævar Arnfjörð Bjarmason
2022-08-04 22:32         ` Emily Noneman
2022-08-05 14:24           ` [PATCH] revision.c: set-up "index_state.repo", don't segfault in pack-objects Ævar Arnfjörð Bjarmason
2022-08-05 14:48             ` Derrick Stolee
2022-08-05 15:25               ` Jeff King [this message]
2022-08-05 16:41                 ` Junio C Hamano
2022-08-08 18:15                   ` Emily Noneman
2022-08-09 12:55                     ` Jeff King
2022-08-09 16:56                       ` Junio C Hamano
2022-08-09 12:54                   ` Jeff King
2022-08-09 16:55                     ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yu02dOo4G8sy8tI6@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=emily.noneman@gmail.com \
    --cc=git@knutwalker.engineer \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).