Skip to contentSkip to conversation

ZSH segmentation fault while completing "git mv dir/"

DISCUSSION Matthieu Moy 5 participants 12 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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,

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Il 11/03/2013 13:30, Matthieu Moy ha scritto:

Quoted 6 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.

Quoted 6 lines

[...]

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-----

#2 lore raw
Quoted 2 lines · Manlio Perillo

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.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#3 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Il 11/03/2013 16:37, Matthieu Moy ha scritto:

Quoted 9 lines

[...]
I could reproduce with ~/.zshrc containing just:

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

autoload -Uz compinit
compinit

Quoted 7 lines

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-----

#4 lore raw

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

#5 lore raw
Quoted 3 lines · Jeff Epler

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).

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#6 lore raw
Quoted 10 lines · Matthieu Moy

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:

contrib/completion/git-completion.zsh +1 -1
@@ -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

#7 lore raw

contrib/completion/git-completion.zsh __gitcomp_file () · line 70

Quoted 11 lines · Felipe Contreras

And this is a workaround:

contrib/completion/git-completion.zsh +1 -1
@@ -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,

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#8 lore raw
Quoted 8 lines · Matthieu Moy
Quoted 6 lines · Felipe Contreras

And this is a workaround:

contrib/completion/git-completion.zsh +0 -0
@@ -66,7 +66,7 @@ __gitcomp_file ()
 
Quoted 8 lines

contrib/completion/git-completion.zsh __gitcomp_file () · line 70

Quoted 5 lines
contrib/completion/git-completion.zsh +1 -1
        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?

Quoted 2 lines

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

#9 lore raw
Quoted 4 lines · Junio C Hamano

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.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#10 lore raw
In reply to Matthieu Moy

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Il 02/04/2013 16:32, Matthieu Moy ha scritto:

Quoted 8 lines
Quoted 6 lines · Felipe Contreras

And this is a workaround:

contrib/completion/git-completion.zsh +0 -0
@@ -66,7 +66,7 @@ __gitcomp_file ()
 
Quoted 10 lines

contrib/completion/git-completion.zsh __gitcomp_file () · line 70

Quoted 5 lines
contrib/completion/git-completion.zsh +1 -1
        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-----

#11 lore raw
Quoted 1 line · Manlio Perillo

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.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/