# [BUG] git cherry-pick segfaults with local changes in working directory

4 messages from 2017-06-15 to 2017-06-15. Participants: Sebastian Dröge, Jeff King.
Thread: https://gitlist.dev/t/46185

## Sebastian Dröge, 2017-06-15 09:11

Subject: [BUG] git cherry-pick segfaults with local changes in working directory
Message-ID: <1497517910.2239.105.camel@centricular.com>
URL: https://gitlist.dev/e/1497517910.2239.105.camel%40centricular.com

```
Hi,

This is with git 2.11.0 (Debian 2.11.0-4) and can be reproduced with
the packed checkout here:
  https://people.freedesktop.org/~slomo/git-cherry-pick-segfault_gst-plugins-good.tar.xz

$ tar xf git-cherry-pick-segfault_gst-plugins-good.tar.xz
$ cd gst-plugins-good
$ git cherry-pick 0421fb04470af90e8810e7e5e69955d3192896ba
Segmentation fault (core dumped)


Without local changes (e.g. after "git stash") it works fine. Also note
that the commit that is cherry-picked does not contain any changes to
files that have local changes.


Backtrace below:

Thread 1 "git" received signal SIGSEGV, Segmentation fault.
add_index_entry_with_check (option=0, ce=0x0, istate=0x555555993900 <the_index>) at read-cache.c:1012
1012	read-cache.c: No such file or directory.
(gdb) bt
#0  add_index_entry_with_check (option=0, ce=0x0, istate=0x555555993900 <the_index>) at read-cache.c:1012
#1  add_index_entry (istate=0x555555993900 <the_index>, ce=0x0, option=0) at read-cache.c:1061
#2  0x0000555555646df6 in merge_content (o=o@entry=0x7fffffffd550, 
    path=path@entry=0x555555a461c0 "docs/plugins/inspect/plugin-shout2send.xml", o_oid=<optimized out>, 
    o_oid@entry=0x555555a42adc, o_mode=o_mode@entry=33188, a_oid=a_oid@entry=0x555555a42af4, 
    a_mode=a_mode@entry=33188, b_oid=0x555555a42b0c, b_mode=33188, rename_conflict_info=0x555555a45fa0)
    at merge-recursive.c:1727
#3  0x0000555555647a1d in process_entry (entry=<optimized out>, path=<optimized out>, o=0x7fffffffd550)
    at merge-recursive.c:1885
#4  merge_trees (o=o@entry=0x7fffffffd550, head=head@entry=0x5555559b7c98, merge=<optimized out>, 
    merge@entry=0x5555559b7c70, common=<optimized out>, common@entry=0x5555559b7cc0, 
    result=result@entry=0x7fffffffd530) at merge-recursive.c:1948
#5  0x000055555568a248 in do_recursive_merge (opts=0x7fffffffdcc0, msgbuf=0x7fffffffd510, 
    head=0x7fffffffd620 "\246\256՝s8J\273ݵ\241y\303#j\277\211\266\\\n\377\177", next_label=<optimized out>, 
    base_label=<optimized out>, next=<optimized out>, base=<optimized out>) at sequencer.c:389
#6  do_pick_commit (command=TODO_PICK, commit=commit@entry=0x5555559a7c60, opts=opts@entry=0x7fffffffdcc0)
    at sequencer.c:757
#7  0x000055555568baa3 in single_pick (opts=0x7fffffffdcc0, cmit=0x5555559a7c60) at sequencer.c:1329
#8  sequencer_pick_revisions (opts=0x7fffffffdcc0) at sequencer.c:1378
#9  0x00005555555d34cf in run_sequencer (argc=1, argc@entry=2, argv=argv@entry=0x7fffffffe0c0, 
    opts=<optimized out>, opts@entry=0x7fffffffdcc0) at builtin/revert.c:178
#10 0x00005555555d3928 in cmd_cherry_pick (argc=2, argv=0x7fffffffe0c0, prefix=<optimized out>)
    at builtin/revert.c:203
#11 0x0000555555566205 in run_builtin (argv=<optimized out>, argc=<optimized out>, p=<optimized out>)
    at git.c:373
#12 handle_builtin (argc=2, argv=0x7fffffffe0c0) at git.c:572
#13 0x00005555555665a2 in run_argv (argv=0x7fffffffde60, argcp=0x7fffffffde6c) at git.c:630
#14 cmd_main (argc=<optimized out>, argv=<optimized out>) at git.c:707
#15 0x00005555555655d2 in main (argc=3, argv=0x7fffffffe0b8) at common-main.c:40

-- 
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
```

## Jeff King, 2017-06-15 10:32

Subject: Re: [BUG] git cherry-pick segfaults with local changes in working directory
Message-ID: <20170615103215.45sp5adzu6zcorct@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20170615103215.45sp5adzu6zcorct%40sigill.intra.peff.net
In-Reply-To: <1497517910.2239.105.camel@centricular.com>

```
On Thu, Jun 15, 2017 at 12:11:50PM +0300, Sebastian Dröge wrote:

> This is with git 2.11.0 (Debian 2.11.0-4) and can be reproduced with
> the packed checkout here:
>   https://people.freedesktop.org/~slomo/git-cherry-pick-segfault_gst-plugins-good.tar.xz
> 
> $ tar xf git-cherry-pick-segfault_gst-plugins-good.tar.xz
> $ cd gst-plugins-good
> $ git cherry-pick 0421fb04470af90e8810e7e5e69955d3192896ba
> Segmentation fault (core dumped)

Note that the tarball doesn't have all the necessary objects. Its
.git/objects/info/alternates points to another full clone of
git://anongit.freedesktop.org/gstreamer/gst-plugins-good.

The segfault was fixed in 55e9f0e5c (merge-recursive: handle NULL in
add_cacheinfo() correctly, 2016-11-26), which is in v2.11.1.

Curiously, after the fix we print:

error: addinfo_cache failed for path 'docs/plugins/inspect/plugin-shout2send.xml'

but the cherry-pick succeeds anyway. I'm not sure if that's a bug or
not.

-Peff

```

## Sebastian Dröge, 2017-06-15 10:37

Subject: Re: [BUG] git cherry-pick segfaults with local changes in working directory
Message-ID: <1497523056.2239.107.camel@centricular.com>
URL: https://gitlist.dev/e/1497523056.2239.107.camel%40centricular.com
In-Reply-To: <20170615103215.45sp5adzu6zcorct@sigill.intra.peff.net>

```
Hi Jeff,

Thanks for the fast reply!

On Thu, 2017-06-15 at 06:32 -0400, Jeff King wrote:
> On Thu, Jun 15, 2017 at 12:11:50PM +0300, Sebastian Dröge wrote:
> 
> > This is with git 2.11.0 (Debian 2.11.0-4) and can be reproduced with
> > the packed checkout here:
> >   https://people.freedesktop.org/~slomo/git-cherry-pick-segfault_gst-plugins-good.tar.xz
> > 
> > $ tar xf git-cherry-pick-segfault_gst-plugins-good.tar.xz
> > $ cd gst-plugins-good
> > $ git cherry-pick 0421fb04470af90e8810e7e5e69955d3192896ba
> > Segmentation fault (core dumped)
> 
> Note that the tarball doesn't have all the necessary objects. Its
> .git/objects/info/alternates points to another full clone of
> git://anongit.freedesktop.org/gstreamer/gst-plugins-good.

Ah good to know, I thought this only happens if you clone with
--reference and not otherwise.

> The segfault was fixed in 55e9f0e5c (merge-recursive: handle NULL in
> add_cacheinfo() correctly, 2016-11-26), which is in v2.11.1.

I can confirm that this also fixes my specific problem. Thanks!

-- 
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
```

## Jeff King, 2017-06-15 13:03

Subject: Re: [BUG] git cherry-pick segfaults with local changes in working directory
Message-ID: <20170615130331.tak725h2i3fe7npw@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20170615130331.tak725h2i3fe7npw%40sigill.intra.peff.net
In-Reply-To: <1497523056.2239.107.camel@centricular.com>

```
On Thu, Jun 15, 2017 at 01:37:36PM +0300, Sebastian Dröge wrote:

> > Note that the tarball doesn't have all the necessary objects. Its
> > .git/objects/info/alternates points to another full clone of
> > git://anongit.freedesktop.org/gstreamer/gst-plugins-good.
> 
> Ah good to know, I thought this only happens if you clone with
> --reference and not otherwise.

If you do a local-filesystem clone of a repository with alternates, the
clone will have the same alternates. So I'm guessing you may have done
such a clone of your --reference repository as part of preparing the
tarball.

-Peff

```
