threads / discuss / 9224

git stash apply segfaulting when called in subdir

Subject: git stash apply segfaulting when called in subdir

## tl;dr

7 messages between Jul 25, 2007 and Jul 26, 2007.

replies: 6people: 5as markdown or json

Uwe Kleine-König· Jul 25, 2007, 21:23 UTC · lore
Hello,
I did not do much testing and didn't look into the issue yet:

zeisberg@cassiopeia:/tmp$ mkdir repo; cd repo; git init Initialized empty Git repository in .git/

zeisberg@cassiopeia:/tmp/repo$ mkdir dir; echo one > file; echo two > dir/file
zeisberg@cassiopeia:/tmp/repo$ git add file dir/file
zeisberg@cassiopeia:/tmp/repo$ git commit -m tralala
Created initial commit 265b7d7: tralala
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 dir/file
 create mode 100644 file
zeisberg@cassiopeia:/tmp/repo$ echo three >> file

zeisberg@cassiopeia:/tmp/repo$ git stash Saved "WIP on master: 265b7d7... tralala" HEAD is now at 265b7d7... tralala

zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789' /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault git-merge-recursive $b_tree -- $c_tree $w_tree

Best regards Uwe

-- 
Uwe Kleine-König

http://www.google.com/search?q=1+newton+in+kg*m+%2F+s%5E2
Junio C Hamano· Jul 25, 2007, 22:28 UTC · re: Uwe Kleine-König · lore

Re: git stash apply segfaulting when called in subdir

Uwe Kleine-König  <ukleinek@informatik.uni-freiburg.de> writes:
Show 22 quoted lines
> zeisberg@cassiopeia:/tmp$ mkdir repo; cd repo; git init
> Initialized empty Git repository in .git/
>
> zeisberg@cassiopeia:/tmp/repo$ mkdir dir; echo one > file; echo two > dir/file
>
> zeisberg@cassiopeia:/tmp/repo$ git add file dir/file
>
> zeisberg@cassiopeia:/tmp/repo$ git commit -m tralala
> Created initial commit 265b7d7: tralala
>  2 files changed, 2 insertions(+), 0 deletions(-)
>  create mode 100644 dir/file
>  create mode 100644 file
>
> zeisberg@cassiopeia:/tmp/repo$ echo three >> file
>
> zeisberg@cassiopeia:/tmp/repo$ git stash
> Saved "WIP on master: 265b7d7... tralala"
> HEAD is now at 265b7d7... tralala
>
> zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
> error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
> /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree

This probably is a merge-recursive bug, but in the meantime, I think this should fix it.

---
 git-stash.sh |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/git-stash.sh b/git-stash.sh
index de13dd1..d9cd42d 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -6,6 +6,7 @@ USAGE='[ | list | show | apply | clear]'
 SUBDIRECTORY_OK=Yes
 . git-sh-setup
 require_work_tree
+cd_to_toplevel
 
 TMP="$GIT_DIR/.git-stash.$$"
 trap 'rm -f "$TMP-*"' 0
Johannes Schindelin· Jul 25, 2007, 23:01 UTC · re: Junio C Hamano · lore

Re: git stash apply segfaulting when called in subdir

Hi,
On Wed, 25 Jul 2007, Junio C Hamano wrote:
Show 45 quoted lines
> Uwe Kleine-König  <ukleinek@informatik.uni-freiburg.de> writes:
> 
> > zeisberg@cassiopeia:/tmp$ mkdir repo; cd repo; git init
> > Initialized empty Git repository in .git/
> >
> > zeisberg@cassiopeia:/tmp/repo$ mkdir dir; echo one > file; echo two > dir/file
> >
> > zeisberg@cassiopeia:/tmp/repo$ git add file dir/file
> >
> > zeisberg@cassiopeia:/tmp/repo$ git commit -m tralala
> > Created initial commit 265b7d7: tralala
> >  2 files changed, 2 insertions(+), 0 deletions(-)
> >  create mode 100644 dir/file
> >  create mode 100644 file
> >
> > zeisberg@cassiopeia:/tmp/repo$ echo three >> file
> >
> > zeisberg@cassiopeia:/tmp/repo$ git stash
> > Saved "WIP on master: 265b7d7... tralala"
> > HEAD is now at 265b7d7... tralala
> >
> > zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
> > error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
> > /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree
> 
> This probably is a merge-recursive bug, but in the meantime,
> I think this should fix it.
> 
> ---
> 
>  git-stash.sh |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/git-stash.sh b/git-stash.sh
> index de13dd1..d9cd42d 100755
> --- a/git-stash.sh
> +++ b/git-stash.sh
> @@ -6,6 +6,7 @@ USAGE='[ | list | show | apply | clear]'
>  SUBDIRECTORY_OK=Yes
>  . git-sh-setup
>  require_work_tree
> +cd_to_toplevel
>  
>  TMP="$GIT_DIR/.git-stash.$$"
>  trap 'rm -f "$TMP-*"' 0
It does... And here is a test case:

-- snipsnap -- [PATCH] Test "stash apply" in a subdirectory

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 t/t3903-stash.sh |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 392ac1c..9e363fd 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -66,4 +66,18 @@ test_expect_success 'apply stashed changes (including index)' '
 	test 1 = $(git show HEAD:file)
 '
 
+test_expect_success 'apply in subdir' '
+	git --git-dir=new init &&
+	cd new &&
+	mkdir dir &&
+	echo one > file &&
+	echo two > dir/file &&
+	git add file dir/file &&
+	git commit -m first &&
+	echo three >> file &&
+	git stash &&
+	cd dir &&
+	git stash apply
+'
+
 test_done
Jeff King· Jul 26, 2007, 05:07 UTC · re: Junio C Hamano · lore

Re: git stash apply segfaulting when called in subdir

On Wed, Jul 25, 2007 at 03:28:12PM -0700, Junio C Hamano wrote:
Show 6 quoted lines
> > zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
> > error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
> > /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree
> 
> This probably is a merge-recursive bug, but in the meantime,
> I think this should fix it.

The merge-recursive bug is simply a failure to check for invalid input. Patch to at least print and die rather than segfault is below. Technically the error could be from a tag dereference, too, so maybe the error message should be more exact?

-- >8 -- merge-recursive: don't segfault on missing input objects

This should generally never happen, but it's nicer to report an error than to segfault.

Signed-off-by: Jeff King <peff@peff.net>
---
 merge-recursive.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index c8539ec..2764e61 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1692,6 +1692,8 @@ static struct commit *get_ref(const char *ref)
 	if (get_sha1(ref, sha1))
 		die("Could not resolve ref '%s'", ref);
 	object = deref_tag(parse_object(sha1), ref, strlen(ref));
+	if (!object)
+		die("Object does not exist: %s", ref);
 	if (object->type == OBJ_TREE)
 		return make_virtual_commit((struct tree*)object,
 			better_branch_name(ref));
-- 
1.5.3.rc3.818.gc1dc7-dirty
Johannes Schindelin· Jul 26, 2007, 05:40 UTC · re: Jeff King · lore

Re: git stash apply segfaulting when called in subdir

Hi,
On Thu, 26 Jul 2007, Jeff King wrote:
Show 10 quoted lines
> On Wed, Jul 25, 2007 at 03:28:12PM -0700, Junio C Hamano wrote:
> 
> > > zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
> > > error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
> > > /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree
> > 
> > This probably is a merge-recursive bug, but in the meantime,
> > I think this should fix it.
> 
> The merge-recursive bug is simply a failure to check for invalid input.
No it is not.

The objects are there. But the objects cannot be found, since merge-recursive cannot go to top level.

Ciao, Dscho

Jeff King· Jul 26, 2007, 05:48 UTC · re: Johannes Schindelin · lore

Re: git stash apply segfaulting when called in subdir

On Thu, Jul 26, 2007 at 06:40:44AM +0100, Johannes Schindelin wrote:
Show 6 quoted lines
> > The merge-recursive bug is simply a failure to check for invalid input.
> 
> No it is not.
> 
> The objects are there.  But the objects cannot be found, since 
> merge-recursive cannot go to top level.

Fair enough, I should have looked a little further. However, I still wonder if it's better to report an error than to segfault.

-Peff
Steven Walter· Jul 25, 2007, 22:32 UTC · re: Uwe Kleine-König · lore

Re: git stash apply segfaulting when called in subdir

On Wed, Jul 25, 2007 at 11:23:11PM +0200, Uwe Kleine-König wrote:
> zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
> error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
> /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree
I've been seeing this, as well.
-- 
-Steven Walter <stevenrwalter@gmail.com>
"A human being should be able to change a diaper, plan an invasion,
butcher a hog, conn a ship, design a building, write a sonnet, balance
accounts, build a wall, set a bone, comfort the dying, take orders,
give orders, cooperate, act alone, solve equations, analyze a new
problem, pitch manure, program a computer, cook a tasty meal, fight
efficiently, die gallantly. Specialization is for insects."
   -Robert Heinlein

← back to recent threads