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
Crash when throwing an exception with a malicious __hash__ override #73148
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=Noneclosed_at=<Date2018-06-03.09:59:49.342>created_at=<Date2016-12-13.16:28:07.836>labels= ['interpreter-core', '3.7']
title='Crash when throwing an exception with a malicious __hash__ override'updated_at=<Date2018-06-03.09:59:49.341>user='https://github.com/JelleZijlstra'
I have reproduced this with Python 3.3, 3.4, 3.5, and 3.6; I assume it's been present throughout the 3 series.
This is because print_exception_recursive in pythonrun.c keeps following the __cause__ chain, and here the exception is its own __cause__. It uses a set to ensure that it breaks cycles, but that doesn't help here because of the exception's incorrect __hash__ method.
Is this something that needs to be defended against? My understanding is that it's pretty easy to segfault CPython in a number of ways if you can execute 100% arbitrary code. The only way to cause this problem is if you can define malicious exceptions and cause one to be raised from itself, neither of which occurs in reasonable code.
xcombelle commented on Dec 22, 2016
xcombellemannequin
Mannequin
More actions
To my knowledge it is not the kind of arbitrary code which could segfault python code. It is far different for example that the fact by using bytecode magic you can segfault the interpreter, as this last case is explicitly warned in documentation.
Activity
JelleZijlstra commentedon Dec 13, 2016
$ cat baderror.py class BadError(Exception): def __init__(self): self.i = 0I have reproduced this with Python 3.3, 3.4, 3.5, and 3.6; I assume it's been present throughout the 3 series.
This is because print_exception_recursive in pythonrun.c keeps following the __cause__ chain, and here the exception is its own __cause__. It uses a set to ensure that it breaks cycles, but that doesn't help here because of the exception's incorrect __hash__ method.
MojoVampire commentedon Dec 13, 2016
Is this something that needs to be defended against? My understanding is that it's pretty easy to segfault CPython in a number of ways if you can execute 100% arbitrary code. The only way to cause this problem is if you can define malicious exceptions and cause one to be raised from itself, neither of which occurs in reasonable code.
xcombelle commentedon Dec 22, 2016
To my knowledge it is not the kind of arbitrary code which could segfault python code. It is far different for example that the fact by using bytecode magic you can segfault the interpreter, as this last case is explicitly warned in documentation.
serhiy-storchaka commentedon Mar 22, 2018
Seems it was fixed somewhere between 3.6.3 and 3.6.5+.
3.5 is now in security-only fixes stage, and this doesn't look like a security issue.
serhiy-storchaka commentedon Jun 3, 2018
It was fixed in bpo-28603.