-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Segfault when raising MemoryError #85820
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
Comments
First of all, I guess this is a somewhat obscure error that is unlikely to occur in a usual context, nevertheless IMO worth reporting. We observed this when unit-testing custom exception reporting mechanism, raising different exceptions in different contexts and then analyzing whether they are processed correctly. This is a somewhat dull example I managed to extract from our tests: from pathlib import Path
from unittest.mock import patch
class TestException(MemoryError):
pass
class report_ctx:
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
report(exc_value)
class raises:
def __init__(self, ex):
self.ex = ex
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
return issubclass(exc_type, self.ex)
def report(ex):
pass
def error():
raise MemoryError
modname = Path(__file__).stem
for _ in range(10):
with patch(f"{modname}.report"):
with raises(MemoryError), report_ctx():
raise MemoryError
with raises(TestException):
raise TestException
with raises(MemoryError):
error() that yields: Fatal Python error: Segmentation fault Current thread 0x00007fcf0833b740 (most recent call first): |
If this is of any help, I've set up an example repository containing the snippet: https://github.com/hoefling/bpo-issue-41654 Here are the results of running the snippet in Travis with Python 3.{5-10} and Pypy 3.6: https://travis-ci.com/github/hoefling/bpo-issue-41654 |
Aha, interesting bug report. I attached a simplified reproducer. Output with a Python built in debug mode: Current thread 0x00007efd7a2d0740 (most recent call first): |
Hm, Looks like we need check the double free risk of |
The problem is that the deallocator of MemoryError class is not taking into account subclasses for the freelist management, but the allocator (tp_new) is. |
Thanks for the fix Pablo! Thanks for the funny bug report Oleg Hoefling! I didn't expect that anyone would ever subclass MemoryError. |
"AMD64 Arch Linux Asan 3.8" buildbot logs a compiler warning: Objects/exceptions.c: In function ‘MemoryError_dealloc’: |
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: