You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python SEGFAULT on tuple.__repr__ and str() #44763
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/brettcannon'closed_at=<Date2007-09-30.19:46:02.886>created_at=<Date2007-03-22.22:00:13.000>labels= ['interpreter-core', 'type-crash']
title='Python SEGFAULT on tuple.__repr__ and str()'updated_at=<Date2007-09-30.20:37:42.555>user='https://bugs.python.org/ludvigericson'
When one uses a class that has derived BaseException in one way or another and uses an invalid super() and calls a function upon that object, Python dies with SIGSEGV.
I could reproduce this on two different Python 2.5 installations.
This is as much as I could get from gdb:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1211660624 (LWP 30234)]
0xb7ea601c in _PyObject_GC_Malloc () from /usr/lib/libpython2.5.so.1.0
(gdb) bt
#0 0xb7ea601c in _PyObject_GC_Malloc () from /usr/lib/libpython2.5.so.1.0 #1 0xb7ea613b in _PyObject_GC_NewVar () from /usr/lib/libpython2.5.so.1.0 #2 0xb7e4abe4 in PyTuple_New () from /usr/lib/libpython2.5.so.1.0 #3 0xb7e4b48d in ?? () from /usr/lib/libpython2.5.so.1.0 #4 0x00000001 in ?? () #5 0x00000000 in ?? ()
It might be added that this works (throws an exception) in python 2.4 (though, BaseException does not exist there):
TypeError: super() argument 1 must be type, not classobj
This is not new in 2.5. That is does not work with super() in 2.4 is because in 2.4 exceptions are old-style classes.
Look at this:
>>> classX(Exception):
... def__init__(self):
... Exception.__init__(self, self)
...
>>> x=X()
>>> str(x)
[1] 4396 segmentation fault python2.4
The problem is that str(x) calls str(x) etc.
therve commented on Aug 30, 2007
thervemannequin
Mannequin
More actions
Here is a patch correcting the problem, with tests. It doesn't have much
to do with exception, it's mainly a problem with PyObject_Str and
PyObject_Repr, that I corrected with Py_EnterRecursiveCall calls.
Maybe the bug should be reclassified, at least the title changed.
Minor note: The patch mixes tabs and spaces. AFAIK, PEP-7 says to use
four spaces when making new code, and follow suite in legacy, or convert it.
therve commented on Sep 6, 2007
thervemannequin
Mannequin
More actions
object.c is already inconsistent about tabs and space :). It may be
better to fix it in the commit, not to clutter the patch. But I can
provide a new patch if necessary.
ludvigericson commented on Sep 6, 2007
ludvigericsonmannequin
MannequinAuthor
More actions
Hm, may be so.
Feel free to change title/severity if you'd like to.
Both fail because BaseException uses the str/repr of its arguments to
construct what string to return. When it's itself it just goes on
forever trying to get the next object's representation.
The repr issue might be fixed by looking at how lists catch loops in
themselves (don't remember the exact C function). Either way it is not
really str/repr that is causing the issue but exceptions for not
worrying about possible recursion thanks to using the str/repr of
contained objects.
changed the title [-]Python SEGFAULT on invalid superclass access[/-][+]Python SEGFAULT on tuple.__repr__ and str()[/+]on Sep 12, 2007
therve commented on Sep 13, 2007
thervemannequin
Mannequin
More actions
I think it could be solved both the same way: if tuple repr is wrong,
there are probably some other repr code that is wrong too, so fixing
PyObject_Repr is safer.
Activity
ludvigericson commentedon Mar 22, 2007
When one uses a class that has derived BaseException in one way or another and uses an invalid super() and calls a function upon that object, Python dies with SIGSEGV.
I could reproduce this on two different Python 2.5 installations.
This is as much as I could get from gdb:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1211660624 (LWP 30234)]
0xb7ea601c in _PyObject_GC_Malloc () from /usr/lib/libpython2.5.so.1.0
(gdb) bt
#0 0xb7ea601c in _PyObject_GC_Malloc () from /usr/lib/libpython2.5.so.1.0
#1 0xb7ea613b in _PyObject_GC_NewVar () from /usr/lib/libpython2.5.so.1.0
#2 0xb7e4abe4 in PyTuple_New () from /usr/lib/libpython2.5.so.1.0
#3 0xb7e4b48d in ?? () from /usr/lib/libpython2.5.so.1.0
#4 0x00000001 in ?? ()
#5 0x00000000 in ?? ()
ludvigericson commentedon Mar 22, 2007
It might be added that this works (throws an exception) in python 2.4 (though, BaseException does not exist there):
TypeError: super() argument 1 must be type, not classobj
birkenfeld commentedon Mar 22, 2007
The problem is that str(x) calls str(x) etc.
therve commentedon Aug 30, 2007
Here is a patch correcting the problem, with tests. It doesn't have much
to do with exception, it's mainly a problem with PyObject_Str and
PyObject_Repr, that I corrected with Py_EnterRecursiveCall calls.
Maybe the bug should be reclassified, at least the title changed.
ludvigericson commentedon Aug 30, 2007
Minor note: The patch mixes tabs and spaces. AFAIK, PEP-7 says to use
four spaces when making new code, and follow suite in legacy, or convert it.
therve commentedon Sep 6, 2007
object.c is already inconsistent about tabs and space :). It may be
better to fix it in the commit, not to clutter the patch. But I can
provide a new patch if necessary.
ludvigericson commentedon Sep 6, 2007
Hm, may be so.
Feel free to change title/severity if you'd like to.
birkenfeld commentedon Sep 12, 2007
Brett, you recently fixed an infinite recursion crasher, right?
brettcannon commentedon Sep 12, 2007
So the first example (in msg31624) crashes because of infinite recursion
with the repr of exceptions::
bpo-7771 0x00065178 in BaseException_repr (self=0x5dc6b8) at
Objects/exceptions.c:128
bpo-7772 0x0001d90c in PyObject_Repr (v=0x5dc6b8) at Objects/object.c:362
bpo-7773 0x0008c180 in tuplerepr (v=0x5dad58) at Objects/tupleobject.c:221
The second one in msg31626 dies because of the str of exceptions::
bpo-3839 0x0001dd88 in PyObject_Str (v=0x5dc6b8) at Objects/object.c:427
bpo-3840 0x00065120 in BaseException_str (self=0x5dc6b8) at
Objects/exceptions.c:110
bpo-3841 0x0001dc0c in _PyObject_Str (v=0x5dc6b8) at Objects/object.c:407
Both fail because BaseException uses the str/repr of its arguments to
construct what string to return. When it's itself it just goes on
forever trying to get the next object's representation.
The repr issue might be fixed by looking at how lists catch loops in
themselves (don't remember the exact C function). Either way it is not
really str/repr that is causing the issue but exceptions for not
worrying about possible recursion thanks to using the str/repr of
contained objects.
3 remaining items
[-]Python SEGFAULT on invalid superclass access[/-][+]Python SEGFAULT on tuple.__repr__ and str()[/+][-]Python SEGFAULT on invalid superclass access[/-][+]Python SEGFAULT on tuple.__repr__ and str()[/+]therve commentedon Sep 13, 2007
I think it could be solved both the same way: if tuple repr is wrong,
there are probably some other repr code that is wrong too, so fixing
PyObject_Repr is safer.
birkenfeld commentedon Sep 20, 2007
I don't have a specific opinion on this; the usage of
Py_EnterRecursiveCall/Py_ReprEnter certainly looks correct.
brettcannon commentedon Sep 30, 2007
Applied in r58288. If I did something stupid or people don't want the
overhead they can yell at the commit. =)
brettcannon commentedon Sep 30, 2007
And fixed in r58289.