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
Double decref and dereferencing after decref in int() #60264
Comments
In function convert_integral_to_int() in file Objects/abstract.c integral double decrefed and dereferenced after decrefing if returned value of __int__() is not int. Python 3.3 only affected. Here is a patch. |
Nice catch! And indeed, the following code generates a segfault on my machine: class B(object):
def __int__(self):
return 43.0
class A(object):
def __trunc__(self):
return B()
int(A()) The patch should probably include a regression test. |
I was going to give similar example and assign crash type to issue, but on my machine it does not generate a segfault.
Someone borrowed Guido's time machine and have already done this test (see NonIntegral in Lib/test/test_int.py). |
That test doesn't look quite the same, though: the return value of __trunc__ is an object that has __trunc__ rather than __int__. And all the existing tests pass on my machine without issues. |
Here's patch that adds a regression test. |
Ah, it generates a segfault in debug mode. LGTM. |
New changeset 690287f8ea95 by Mark Dickinson in branch 'default': |
Applied. Thanks! I'm not sure whether this is worthy of inclusion in Python 3.3.0; on one hand, it's a segfault from core Python. On the other, it doesn't look that easy to trigger by accident. On balance, I'd say it's safe to wait for Python 3.3.1 for this. Adding Georg to the nosy in case he disagrees. |
Serhiy, I wonder how you found this :) |
I just looked at the code for bpo-16036. |
Applied: d23eb81bd482. |
New changeset d23eb81bd482 by Mark Dickinson in branch 'default': |
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: