New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python SEGFAULT on tuple.__repr__ and str() #44763
Comments
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. Reproduce code:
>>> class X(BaseException):
... def __init__(self):
... super(X, self).__init__(self)
...
>>> X()
Segmentation fault I could reproduce this on two different Python 2.5 installations. This is as much as I could get from gdb: |
It might be added that this works (throws an exception) in python 2.4 (though, BaseException does not exist there): |
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:
>>> class X(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. |
Here is a patch correcting the problem, with tests. It doesn't have much 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 |
object.c is already inconsistent about tabs and space :). It may be |
Hm, may be so. Feel free to change title/severity if you'd like to. |
Brett, you recently fixed an infinite recursion crasher, right? |
So the first example (in msg31624) crashes because of infinite recursion bpo-7771 0x00065178 in BaseException_repr (self=0x5dc6b8) at 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 Both fail because BaseException uses the str/repr of its arguments to The repr issue might be fixed by looking at how lists catch loops in |
OK, so I have attached a possible patch. I found out that Same goes for object.__str__; it didn't think about a type's tp_str Assigning back to Georg to make sure I am not doing something stupid nor I have not written tests yet as they are rather difficult to do for what |
I think it could be solved both the same way: if tuple repr is wrong, |
I don't have a specific opinion on this; the usage of |
Applied in r58288. If I did something stupid or people don't want the |
And fixed in r58289. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: