seg fault with :python print

281 views
Skip to first unread message

William E. Skeith III

unread,
Apr 13, 2012, 4:07:27 AM4/13/12
to vim...@vim.org
Hello,

I am writing to report a potential bug.  To reproduce:

    :python print "hello"

This gives me a segmentation fault.  A few other arch linux users have
confirmed the issue, and noted that other python commands still function:

https://bbs.archlinux.org/viewtopic.php?pid=1086827

Here is the version information:

http://pastebin.com/QHhjnZdP

Please let me know anything I can do to help.  Thanks.

-WES

lilydjwg

unread,
Apr 13, 2012, 6:46:47 AM4/13/12
to vim...@googlegroups.com
On Fri, Apr 13, 2012 at 01:07:27AM -0700, William E. Skeith III wrote:
> Hello,
>
> I am writing to report a potential bug.  To reproduce:
>
>     :python print "hello"
>
> This gives me a segmentation fault.  A few other arch linux users have
> confirmed the issue, and noted that other python commands still function:
>
> https://bbs.archlinux.org/viewtopic.php?pid=1086827
>
> Here is the version information:
>
> http://pastebin.com/QHhjnZdP

FYI, my vim 7.3.494 doesn't crash. I'm also using Arch Linux (64bit) but
the Python 2.7 is dynamic loaded.

--
Best regards,
lilydjwg

Linux Vim Python 我的博客:
http://lilydjwg.is-programmer.com/
--
A: Because it obfuscates the reading.
Q: Why is top posting so bad?

Taylor Hedberg

unread,
Apr 13, 2012, 10:00:38 AM4/13/12
to vim...@googlegroups.com, vim...@vim.org
Arch x86_64 here and I can reproduce the segfault as well. My Vim is
compiled with +python but not +python3, if that makes any difference.

Thomas Dziedzic

unread,
Apr 13, 2012, 10:38:36 AM4/13/12
to vim...@googlegroups.com
On Fri, Apr 13, 2012 at 9:00 AM, Taylor Hedberg <tmhe...@gmail.com> wrote:
> Arch x86_64 here and I can reproduce the segfault as well. My Vim is
> compiled with +python but not +python3, if that makes any difference.

Hi,

I was going to report this when I had more time to debug, but since
people are already posting it here, I will submit what I have.

Yesterday I had a segfault with vim + neocomplcache turned on while
editing a file (reproducible).
The stack trace from that is at: https://gist.github.com/2377278

I can confirm the segfault with :python print "hello"
The stack trace is at: https://gist.github.com/2377276

They crash in the same location:
#0 0x00007ffff4b3f578 in memchr () from /lib/libc.so.6
#1 0x00000000005a96e8 in writer (fn=0x4d5f70 <msg>, str=0x0, n=2) at
if_py_both.h:172
#2 0x00000000005a9912 in OutputWrite (self=<optimized out>,
args=<optimized out>) at if_py_both.h:82

Hope this helps for now.

Nick Walker

unread,
Apr 13, 2012, 4:43:12 PM4/13/12
to vim...@googlegroups.com
On Friday, April 13, 2012 7:38:36 AM UTC-7, Thomas Dziedzic wrote:

I am having this same issue with Arch x86_64 and gvim 7.3.495.

Downgrading to 7.3.475 fixes this. However, rebuilding 475 from source has the same issue as 495.

lilydjwg

unread,
Apr 14, 2012, 2:06:41 AM4/14/12
to vim...@googlegroups.com

Hi, I have updated the source code and tried again, no crash as before.
But the binary from Arch's official package does crash. Also, I tried
using nearly the same config as the Arch one (only one extra '-g' passed
as CFLAGS), it doesn't crash, either.

Christian Brabandt

unread,
Apr 14, 2012, 10:36:29 AM4/14/12
to vim...@googlegroups.com
Hi Thomas!

I really don't know the interface between Vim and python but I wonder
why str is null.
This patch guards against str being Null and should therefore prevent
the segfault.
However, this just means :python print "hello" won't return anything, so
possibly parsing the argument gets wrong somewhere before.

diff --git a/src/if_py_both.h b/src/if_py_both.h
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -74,7 +74,7 @@
char *str = NULL;
int error = ((OutputObject *)(self))->error;

- if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len))
+ if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len) || str == NUL)
return NULL;

Py_BEGIN_ALLOW_THREADS


regards,
Christian

Thomas Dziedzic

unread,
Apr 14, 2012, 1:27:55 PM4/14/12
to vim...@googlegroups.com
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php

Breakpoint 1, OutputWrite (self=0x83d2e0, args=0x7ffff7eda4d0) at
if_py_both.h:77
77 in if_py_both.h
(gdb) info locals
len = 0
str = 0x7ffff4703cb0 "g6"
error = <optimized out>
(gdb) continue
Continuing.

Breakpoint 2, OutputWrite (self=<optimized out>, args=<optimized out>)
at if_py_both.h:80
80 in if_py_both.h
(gdb) info locals
_save = <optimized out>
len = 8
str = 0x0
error = 0

It seems that str is for some reason getting set to null even if
everything appears to be ok..
Nick's comment also makes me think it might possibly have something to
do with the recent gcc 4.7 update.

lilydjwg

unread,
Apr 14, 2012, 2:56:13 PM4/14/12
to vim...@googlegroups.com
On Sat, Apr 14, 2012 at 12:27:55PM -0500, Thomas Dziedzic wrote:
> [...]

>
> It seems that str is for some reason getting set to null even if
> everything appears to be ok..
> Nick's comment also makes me think it might possibly have something to
> do with the recent gcc 4.7 update.

Hi, I just upgraded those packages and compiled if_python.o again, and
I got the same crash. However, it won't crash if I add CFLAGS=-g then
re-compile.

Thomas Dziedzic

unread,
Apr 14, 2012, 3:52:16 PM4/14/12
to vim...@googlegroups.com
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php

I couldn't reproduce this and it still crashes for me with
options=('!buildflags' '!makeflags').
If you could, can you see if you can get the vim PKGBUILD to build
without the segfault?
This will provide a point of reference so I can see what are the exact
changes that are needed to stop the segfault.

lilydjwg

unread,
Apr 15, 2012, 3:14:58 AM4/15/12
to vim...@googlegroups.com
On Sat, Apr 14, 2012 at 02:52:16PM -0500, Thomas Dziedzic wrote:
> On Sat, Apr 14, 2012 at 1:56 PM, lilydjwg <lily...@gmail.com> wrote:
> > On Sat, Apr 14, 2012 at 12:27:55PM -0500, Thomas Dziedzic wrote:
> >> [...]
> >>
> >> It seems that str is for some reason getting set to null even if
> >> everything appears to be ok..
> >> Nick's comment also makes me think it might possibly have something to
> >> do with the recent gcc 4.7 update.
> >
> > Hi, I just upgraded those packages and compiled if_python.o again, and
> > I got the same crash. However, it won't crash if I add CFLAGS=-g then
> > re-compile.
>
> I couldn't reproduce this and it still crashes for me with
> options=('!buildflags' '!makeflags').
> If you could, can you see if you can get the vim PKGBUILD to build
> without the segfault?
> This will provide a point of reference so I can see what are the exact
> changes that are needed to stop the segfault.

After makepkg, I remove gvim-build/src/objects/if_python.o and then run
'make CFLAGS=-g' in 'gvim-build', the resulting 'src/vim' won't crash.

Nothing in PKGBUILD changed except that I commented out the commands
building no-GUI vim since it doesn't support Python.

Bram Moolenaar

unread,
Apr 15, 2012, 10:44:20 AM4/15/12
to Christian Brabandt, vim...@googlegroups.com

Christian Brabandt wrote:

Avoiding a crash is always good. But perhaps there is a better
solution?

--
ARTHUR: Be quiet!
DENNIS: Well you can't expect to wield supreme executive power just 'cause
some watery tart threw a sword at you!
ARTHUR: Shut up!
DENNIS: I mean, if I went around sayin' I was an empereror just because some
moistened bint had lobbed a scimitar at me they'd put me away!
The Quest for the Holy Grail (Monty Python)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Thomas Dziedzic

unread,
Apr 19, 2012, 1:02:25 PM4/19/12
to vim...@googlegroups.com
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php

After exporting the flags with -g as lilydjwg suggested, :python print
"hello" didn't segfault vim.
I am still getting the segfault when trying to autocomplete the string
"collections." with neocomplcache.

The full backtrace (which is different than the original) when it
crashes is at https://gist.github.com/2422281

Thomas Dziedzic

unread,
Apr 19, 2012, 6:59:01 PM4/19/12
to vim...@googlegroups.com

Ok, I'm getting closer to figuring this out, it's caused by having the
-O2 flag there. If you remove -O2 from CFLAGS, there is no crash. I'm
guessing this has something to do with gcc 4.7.0 possibly

Ernie Rael

unread,
Apr 19, 2012, 8:02:21 PM4/19/12
to vim...@googlegroups.com
On 4/19/2012 3:59 PM, Thomas Dziedzic wrote:
> Ok, I'm getting closer to figuring this out, it's caused by having the
> -O2 flag there. If you remove -O2 from CFLAGS, there is no crash. I'm
> guessing this has something to do with gcc 4.7.0 possibly
While it may be an optimizer bug, and things like

> #2 0x00000000005a9912 in OutputWrite (self=<optimized out>, args=<optimized out>) at if_py_both.h:82

make one suspicious. It might be that there is some "lucky" code.

-ernie

James McCoy

unread,
Apr 25, 2012, 11:56:01 AM4/25/12
to vim...@googlegroups.com

It looks like this was caused by http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53084.

Thomas Dziedzic

unread,
Apr 25, 2012, 11:56:11 PM4/25/12
to vim...@googlegroups.com
> It looks like this was caused by
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53084.
>

I will try to see if this was the problem once the next gcc snapshot
comes out (this weekend or next week) and try to report back here.

Thomas Dziedzic

unread,
May 9, 2012, 2:48:59 AM5/9/12
to vim...@googlegroups.com
Just tried out the latest gcc snapshot 4.7-20120505
This segfault still exists so it wasn't caused by gcc bug #53084.
Also, here is a fedora bug report for the same thing:
https://bugzilla.redhat.com/show_bug.cgi?id=817196

Christian Brabandt

unread,
May 9, 2012, 5:29:51 AM5/9/12
to vim...@googlegroups.com
Hi Thomas!
Shouldn't patch 497 avoid the crash?

regards,
Christian

James McCoy

unread,
May 9, 2012, 6:25:57 AM5/9/12
to vim...@googlegroups.com
The day before I posted that email, Debian got an updated gcc-4.7 which
cherry-picked a few fixes from upstream. With that update, I wasn't
able to reproduce the crash anymore. #53084 was the upstream bug that
looked like it was most relevant, but maybe that was only part of the
fix. If you want to dig into it, here's the full list of fixes that
were pulled into the updated package:

* Update to SVN 20120424 (r186746) from the gcc-4_7-branch.
- Fix PR libstdc++/52924, PR libstdc++/52591, PR middle-end/52894,
PR testsuite/53046, PR libstdc++/53067, PR libstdc++/53027,
PR libstdc++/52839, PR bootstrap/52840, PR libstdc++/52689,
PR libstdc++/52699, PR libstdc++/52822, PR libstdc++/52942,
PR middle-end/53084, PR middle-end/52999, PR c/53060,
PR tree-optimizations/52891, PR target/53033, PR target/53020,
PR target/52932, PR middle-end/52939, PR tree-optimization/52969,
PR c/52862, PR target/52775, PR tree-optimization/52943, PR c++/53003,
PR c++/38543, PR c++/50830, PR c++/50303, PR c++/52292, PR c++/52380,
PR c++/52465, PR c++/52824, PR c++/52906.

Cheers,
--
James
GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <jame...@jamessan.com>
signature.asc

Thomas Dziedzic

unread,
May 9, 2012, 11:31:37 AM5/9/12
to vim...@googlegroups.com
yes, but as the commit message suggests: "Avoid the crash, doesn't
really fix the problem."

http://code.google.com/p/vim/source/detail?r=e34c620007be9fd805556c43fe848de521f3b64c

> regards,
> Christian

Thomas Dziedzic

unread,
Jun 12, 2012, 9:56:56 AM6/12/12
to vim...@googlegroups.com
On Tue, Jun 12, 2012 at 7:02 AM, Piotr Skamruk <piotr....@gmail.com> wrote:
> On Saturday, April 14, 2012 4:36:29 PM UTC+2, Christian Brabandt wrote:
>> Hi Thomas!
>> [...]
>> diff --git a/src/if_py_both.h b/src/if_py_both.h
>> --- a/src/if_py_both.h
>> +++ b/src/if_py_both.h
>> @@ -74,7 +74,7 @@
>>      char *str = NULL;
>>      int error = ((OutputObject *)(self))->error;
>>
>> -    if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len))
>> +    if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len) || str == NUL)
>>         return NULL;
>>
>>      Py_BEGIN_ALLOW_THREADS
>
> Thanx for this patch.
> This works for me both on ubuntu and on debian, and now vim stopped to crash with sigsegv.
>

Just an fyi, it is still broken with this patch. It only prevents the
segfault, and doesn't fix the underlying bug.
e.g. :python print 'hi' doesn't segfault anymore, but it also doesn't
print anything which.

The only way I know on how to fix this (not segfault and print) is to
take out -O2 from the CFLAGS.

Cheers

James McCoy

unread,
Jun 16, 2012, 4:13:40 PM6/16/12
to vim...@googlegroups.com
On Tue, Jun 12, 2012 at 08:56:56AM -0500, Thomas Dziedzic wrote:
> Just an fyi, it is still broken with this patch. It only prevents the
> segfault, and doesn't fix the underlying bug.
> e.g. :python print 'hi' doesn't segfault anymore, but it also doesn't
> print anything which.
>
> The only way I know on how to fix this (not segfault and print) is to
> take out -O2 from the CFLAGS.

Or to upgrade GCC to a version (like the recent 4.7.1 release) that doesn't
produce bad code.
signature.asc

Thomas Dziedzic

unread,
Jun 17, 2012, 10:35:02 PM6/17/12
to vim...@googlegroups.com
> Or to upgrade GCC to a version (like the recent 4.7.1 release) that doesn't
> produce bad code.
>
> --
> James
> GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <jame...@jamessan.com>

gcc 4.7.1 still has this problem
Reply all
Reply to author
Forward
0 new messages