threads / discuss / 33155

ZSH segmentation fault while completing "git mv dir/"

Subject: ZSH segmentation fault while completing "git mv dir/"

## tl;dr

12 messages between Mar 11, 2013 and Apr 3, 2013.

replies: 11people: 5as markdown or json

Matthieu Moy· Mar 11, 2013, 12:30 UTC · lore
Hi,

Since the recent update to bash completion, I often get a segmentation fault from ZSH. This is most likely a bug in ZSH, but it would be cool to avoid triggering it from Git.

Steps to reproduce:

moy@anie:/tmp$$ git init zsh Initialized empty Git repository in /tmp/zsh/.git/ moy@anie:/tmp$$ cd zsh/ moy@anie:/tmp/zsh$$ mkdir foo moy@anie:/tmp/zsh$$ touch foo/bar.txt moy@anie:/tmp/zsh$$ git mv foo/zsh: segmentation fault zsh moy@anie:~$ zsh --version zsh 4.3.10 (i686-pc-linux-gnu)

(this is ZSH packaged with Debian stable)
Any ZSH guru to look into it?
Thanks,
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Manlio Perillo· Mar 11, 2013, 15:14 UTC · re: Matthieu Moy · lore

Re: ZSH segmentation fault while completing "git mv dir/"

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Il 11/03/2013 13:30, Matthieu Moy ha scritto:
Show 12 quoted lines
> Hi,
> 
> Since the recent update to bash completion, I often get a segmentation
> fault from ZSH. This is most likely a bug in ZSH, but it would be cool
> to avoid triggering it from Git.
> 
> [...]
> moy@anie:~$ zsh --version
> zsh 4.3.10 (i686-pc-linux-gnu)
> 
> (this is ZSH packaged with Debian stable)
> 

I have the same system, but I can't reproduce the problem. What is the content of your .zshrc file?

Regards  Manlio Perillo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlE99NAACgkQscQJ24LbaURIwgCbB9HmepRfvTqN2vh6H5/Ew7Mw WQMAn3CSiFViQ7j62fuBVKg6WJK+Yg/0 =j4FV -----END PGP SIGNATURE-----

Matthieu Moy· Mar 11, 2013, 15:37 UTC · re: Manlio Perillo · lore

Re: ZSH segmentation fault while completing "git mv dir/"

Manlio Perillo <manlio.perillo@gmail.com> writes:
> I have the same system, but I can't reproduce the problem.
> What is the content of your .zshrc file?
I could reproduce with ~/.zshrc containing just:

---------------------------------------------- fpath=(${HOME}/usr/etc/zsh ${fpath})

autoload -Uz compinit compinit

eval "`dircolors`" zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} ----------------------------------------------

${HOME}/usr/etc/zsh contains two links _git and git-completion.bash pointing to Git's completion scripts in contrib/.

Removing any line aboves removes the segmentation fault.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Manlio Perillo· Mar 11, 2013, 19:33 UTC · re: Matthieu Moy · lore

Re: ZSH segmentation fault while completing "git mv dir/"

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Il 11/03/2013 16:37, Matthieu Moy ha scritto:
Show 16 quoted lines
> [...]
> I could reproduce with ~/.zshrc containing just:
> 
> ----------------------------------------------
> fpath=(${HOME}/usr/etc/zsh ${fpath})
> 
> autoload -Uz compinit
> compinit
> 
> eval "`dircolors`"
> zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
> ----------------------------------------------
> 
> ${HOME}/usr/etc/zsh contains two links _git and git-completion.bash
> pointing to Git's completion scripts in contrib/.
> 

Using this configuration I still can't reproduce the problem, using git v1.8.2-rc3-8-g0c91a6f.

But I'm not a zsh expert.
Regards   Manlio Perillo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlE+MZAACgkQscQJ24LbaUSTuACfYmZV9cvroPzBUdJspw9abh24 fk8AnRTjvCEJ3m8Y2m/5jCIVVNsJAcG7 =5p6c -----END PGP SIGNATURE-----

Jeff Epler· Mar 12, 2013, 01:37 UTC · re: Manlio Perillo · lore

Re: ZSH segmentation fault while completing "git mv dir/"

If it's dependent on eval "`dircolors`", it suggests it might be dependent on the size of the environment. Maybe try with FOO=`perl -e 'print "x"x1000'` for various values of 1000...

Jeff
Matthieu Moy· Mar 12, 2013, 07:53 UTC · re: Jeff Epler · lore

Re: ZSH segmentation fault while completing "git mv dir/"

Jeff Epler <jepler@unpythonic.net> writes:
> If it's dependent on eval "`dircolors`", it suggests it might be
> dependent on the size of the environment.  Maybe try with FOO=`perl -e
> 'print "x"x1000'` for various values of 1000...

It's not this, but I could reduce the problem to a slightly simpler .zshrc:

----------------------------------------------------------------- fpath=(${HOME}/usr/etc/zsh ${fpath})

autoload -Uz compinit compinit

zstyle ':completion:*' list-colors 'rs=0' 'di=01;34' 'ln=01;36' \
 'mh=00' 'pi=40;33' 'so=01;35' 'do=01;35' 'bd=40;33;01' 'cd=40;33;01' \
 'or=40;31;01' 'su=37;41' 'sg=30;43' 'ca=30;41' 'tw=30;42' 'ow=34;42' \
 'st=37;44' 'ex=01;32' '*.tar=01;31' '*.tgz=01;31' '*.arj=01;31'  \
 '*.taz=01;31' '*.lzh=01;31' '*.lzma=01;31' '*.tlz=01;31' '*.txz=01;31' \
 '*.zip=01;31' '*.z=01;31' '*.Z=01;31' '*.dz=01;31' '*.gz=01;31'  \
 '*.lz=01;31' '*.xz=01;31' '*.bz2=01;31' '*.bz=01;31' '*.tbz=01;31'  \
 '*.tbz2=01;31' '*.tz=01;31' '*.deb=01;31' '*.rpm=01;31' '*.jar=01;31' \
 '*.rar=01;31' '*.ace=01;31' '*.pgm=01;35' '*.ppm=01;35'  \
 '*.tga=01;35' '*.xbm=01;35' '*.zoo=01;31' '*.cpio=01;31' '*.7z=01;31' \
 '*.rz=01;31' '*.jpg=01;35' '*.jpeg=01;35' '*.gif=01;35' \
 '*.bmp=01;35' '*.pbm=01;35'
-----------------------------------------------------------------

The problem disapears if I remove one of the arguments after list-colors (I didn't try with each of them, but picking 5 of them randomly and removing it worked), so it seems to be a matter of number of arguments.

On git-completion.bash's side, it's really strange. If I comment out the "case" statement in _git_mv like this, the problem disapears:

_git_mv ()
{
	# case "$cur" in
	# --*)
	# 	__gitcomp "--dry-run"
	# 	return
	# 	;;
	# esac
	if [ $(__git_count_arguments "mv") -gt 0 ]; then
		# We need to show both cached and untracked files (including
		# empty directories) since this may not be the last argument.
		__git_complete_index_file "--cached --others --directory"
	else
		__git_complete_index_file "--cached"
	fi
}

If I add a simple 'echo "$cur" >&2' instead of the case, the problem reappears. Somehow, the fact that I'm accessing $cur seems to create the segfault. Actually, the minimalistic _git_mv reproducing the problem is:

_git_mv ()
{
	echo "$cur"
	[ $(__git_count_arguments "mv") = 1 ]
	__git_complete_index_file "--cached --others --directory"
}
gdb doesn't say much interesting since my ZSH isn't compile with debug:
(gdb) r
Starting program: /usr/bin/zsh 
anie$ cd /tmp/git
anie$ git mv subdir/
Program received signal SIGSEGV, Segmentation fault.
__strlen_sse2 () at ../sysdeps/i386/i686/multiarch/strlen.S:87
87	../sysdeps/i386/i686/multiarch/strlen.S: No such file or directory.
	in ../sysdeps/i386/i686/multiarch/strlen.S
Current language:  auto
The current source language is "auto; currently asm".
(gdb) where
#0  __strlen_sse2 () at ../sysdeps/i386/i686/multiarch/strlen.S:87
#1  0x080ae31d in ztrdup ()
#2  0xb7b9d287 in permmatches () from /usr/lib/zsh/4.3.10/zsh/complete.so
#3  0xb7b9a22e in ?? () from /usr/lib/zsh/4.3.10/zsh/complete.so
#4  0x08098f33 in getstrvalue ()
#5  0x08099e9d in ?? ()
#6  0x0809acd7 in getindex ()
#7  0x0809b3d9 in fetchvalue ()
#8  0x080b0f84 in ?? ()
#9  0x080b49a7 in prefork ()
#10 0x08066cb9 in ?? ()
#11 0x08067151 in ?? ()
#12 0x0806cfc0 in execlist ()
#13 0x0808984c in execif ()
#14 0x080670c6 in ?? ()
#15 0x0806cfc0 in execlist ()
#16 0x0806d69a in execode ()
#17 0x0806d785 in runshfunc ()
#18 0xb7b99a7a in ?? () from /usr/lib/zsh/4.3.10/zsh/complete.so
#19 0x0806d724 in runshfunc ()
#20 0x0806db92 in doshfunc ()
#21 0xb7ba3363 in ?? () from /usr/lib/zsh/4.3.10/zsh/complete.so
#22 0xb7ba44dc in do_completion () from /usr/lib/zsh/4.3.10/zsh/complete.so
#23 0xb7bdaf47 in ?? () from /usr/lib/zsh/4.3.10/zsh/zle.so
#24 0xb7bd5b40 in completecall () from /usr/lib/zsh/4.3.10/zsh/zle.so
#25 0xb7bc6f6e in execzlefunc () from /usr/lib/zsh/4.3.10/zsh/zle.so
#26 0xb7bc72a2 in zlecore () from /usr/lib/zsh/4.3.10/zsh/zle.so
#27 0xb7bc78d5 in zleread () from /usr/lib/zsh/4.3.10/zsh/zle.so
#28 0xb7bc96ff in ?? () from /usr/lib/zsh/4.3.10/zsh/zle.so
#29 0x0807d462 in zleentry ()
#30 0x08080a31 in ingetc ()
#31 0x0807b03c in ?? ()
#32 0x08087fb6 in zshlex ()
#33 0x080a3b4a in parse_event ()
#34 0x0807f2f1 in loop ()
#35 0x080800c6 in zsh_main ()
#36 0x08054cbb in main ()

I can't reproduce the problem with the exact same config and a freshly compiled ZSH (so it's no use reporting the issue to the ZSH developers).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Felipe Contreras· Apr 1, 2013, 10:11 UTC · re: Matthieu Moy · lore

Re: ZSH segmentation fault while completing "git mv dir/"

On Tue, Mar 12, 2013 at 1:53 AM, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:

Show 10 quoted lines
> If I add a simple 'echo "$cur" >&2' instead of the case, the problem
> reappears. Somehow, the fact that I'm accessing $cur seems to create the
> segfault. Actually, the minimalistic _git_mv reproducing the problem is:
>
> _git_mv ()
> {
>         echo "$cur"
>         [ $(__git_count_arguments "mv") = 1 ]
>         __git_complete_index_file "--cached --others --directory"
> }
I managed to reproduce the issue, and to me, this is enough:

_git_mv () { __gitcomp_file 'bar.txt' 'foo/' }

And this is a workaround:
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -66,7 +66,7 @@ __gitcomp_file ()

        local IFS=$'\n'
        compset -P '*[=:]'
-       compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
+       compadd -Q -p "${2-}" -- ${=1} && _ret=0
 }

 _git ()

Cheers.

--
Felipe Contreras
Matthieu Moy· Apr 2, 2013, 14:32 UTC · re: Felipe Contreras · lore

Re: ZSH segmentation fault while completing "git mv dir/"

Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 11 quoted lines
> And this is a workaround:
>
> --- a/contrib/completion/git-completion.zsh
> +++ b/contrib/completion/git-completion.zsh
> @@ -66,7 +66,7 @@ __gitcomp_file ()
>
>         local IFS=$'\n'
>         compset -P '*[=:]'
> -       compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
> +       compadd -Q -p "${2-}" -- ${=1} && _ret=0
>  }

OK, not something we want to apply to git.git, but this means a workaround for users is to create a _git file with this content instead instead of copying/symlinking git-completion.zsh as _git (replace $GIT_ROOT_PATH with the appropriate value):

. $GIT_ROOT_PATH/contrib/completion/git-completion.zsh
# Work around ZSH bug on zsh 4.3.10-dev-1-cvs0720, which segfaults
# when completing "git mv subdir/<tab>" by redefining __gitcomp_file
__gitcomp_file ()
{
	emulate -L zsh
	local IFS=$'\n'
	compset -P '*[=:]'
	# The original had a -f here to indicate file completion.
	compadd -Q -p "${2-}" -- ${=1} && _ret=0
}

(Hope this helps in case someone has the same problem and finds this thread ...)

Thanks,
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Junio C Hamano· Apr 2, 2013, 16:48 UTC · re: Matthieu Moy · lore

Re: ZSH segmentation fault while completing "git mv dir/"

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
Show 16 quoted lines
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> And this is a workaround:
>>
>> --- a/contrib/completion/git-completion.zsh
>> +++ b/contrib/completion/git-completion.zsh
>> @@ -66,7 +66,7 @@ __gitcomp_file ()
>>
>>         local IFS=$'\n'
>>         compset -P '*[=:]'
>> -       compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
>> +       compadd -Q -p "${2-}" -- ${=1} && _ret=0
>>  }
>
> OK, not something we want to apply to git.git, but this means a
> workaround for users is to ...

Would it help users more to have that as part of the instruction at the beginning of contrib/completion/git-completion.zsh where it already says "here is how you use it via fpath", than leaving it here in the list archive?

> (Hope this helps in case someone has the same problem and finds this
> thread ...)
Matthieu Moy· Apr 2, 2013, 17:00 UTC · re: Junio C Hamano · lore

Re: ZSH segmentation fault while completing "git mv dir/"

Junio C Hamano <gitster@pobox.com> writes:
> Would it help users more to have that as part of the instruction at
> the beginning of contrib/completion/git-completion.zsh where it
> already says "here is how you use it via fpath", than leaving it
> here in the list archive?

Juging from the answers I got, I do not think many people are hit by the bug, and the problem will anyway disappear as people update their ZSH, so I'm not sure it's worth the trouble.

This thread is already #1 on google with "git zsh segmentation fault" so it's not terribly difficult to find.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Manlio Perillo· Apr 2, 2013, 20:55 UTC · re: Matthieu Moy · lore

Re: ZSH segmentation fault while completing "git mv dir/"

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Il 02/04/2013 16:32, Matthieu Moy ha scritto:
Show 18 quoted lines
> Felipe Contreras <felipe.contreras@gmail.com> writes:
> 
>> And this is a workaround:
>>
>> --- a/contrib/completion/git-completion.zsh
>> +++ b/contrib/completion/git-completion.zsh
>> @@ -66,7 +66,7 @@ __gitcomp_file ()
>>
>>         local IFS=$'\n'
>>         compset -P '*[=:]'
>> -       compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
>> +       compadd -Q -p "${2-}" -- ${=1} && _ret=0
>>  }
> 
> OK, not something we want to apply to git.git, but this means a
> workaround for users is to create a _git file with this content instead
> instead of copying/symlinking git-completion.zsh as _git (replace
> $GIT_ROOT_PATH with the appropriate value)
By the way: have you filled a bug report to Debian?
Regards  Manlio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlFbRasACgkQscQJ24LbaUTDZQCfbfF5yhxCfUSaWdv0pE7++X3l Lc0AniAw5lEL6iunM+Tw8HvYxGwjuYYh =KpQI -----END PGP SIGNATURE-----

Matthieu Moy· Apr 3, 2013, 08:52 UTC · re: Manlio Perillo · lore

Re: ZSH segmentation fault while completing "git mv dir/"

Manlio Perillo <manlio.perillo@gmail.com> writes:
> By the way: have you filled a bug report to Debian?

No, but this is a bug touching very few users, in Debian stable which is reaching its end of life. I do not think the Debian folks would be interested in fixing this non-security, non-critical bug now.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

← back to recent threads