Open
Description
Crash report
What happened?
It's possible to abort the interpreter by passing a class that has invalid, changing hash values to OrderedDict.setdefault
:
from abc import ABCMeta
from random import randint
large_num = 2**64
class WeirdBase(ABCMeta):
def __hash__(self):
return randint(0, large_num)
class weird_bytes(bytes, metaclass=WeirdBase):
pass
from collections import OrderedDict
obj = OrderedDict()
for x in range(100):
obj.setdefault(weird_bytes, None)
Abort message:
python: Objects/odictobject.c:1036: OrderedDict_setdefault_impl: Assertion `_odict_find_node(self, key) == NULL' failed.
Program received signal SIGABRT, Aborted.
Found using fusil by @vstinner.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.14.0a6+ (heads/main:be2d2181e62, Mar 31 2025, 07:30:17) [GCC 11.4.0]