# Breakpoint 1, encoder_listencode_dict (s=0x405b23fc, acc=0xbfc4038c, dct=, indent_level=0) # at /home/p/Python-3.4.1/Modules/_json.c:1540 # 1540 items = PyMapping_Keys(dct); # (gdb) n # 1541 if (items == NULL) # (gdb) print *items # $1 = {_ob_next = 0x405c8af4, _ob_prev = 0x4059006c, ob_refcnt = 2, ob_type = 0x830e1c0 } # (gdb) n # 1543 if (!PyList_Check(items)) { # (gdb) n # 1547 if (PyList_Sort(items) < 0) # (gdb) n # 1549 nitems = PyList_GET_SIZE(items); # (gdb) n # 1550 for (i = 0; i < nitems; i++) { # (gdb) print nitems # $2 = 1122 # (gdb) n # 1552 key = PyList_GET_ITEM(items, i); # (gdb) n # 1553 value = PyDict_GetItem(dct, key); # (gdb) print *key # $3 = {_ob_next = 0x4058eedc, _ob_prev = 0x40590d1c, ob_refcnt = 1, ob_type = 0x405afd1c} # (gdb) n # # Program received signal SIGSEGV, Segmentation fault. # 0x08108825 in PyType_IsSubtype (a=0xdbdbdbdb, b=0x830f1a0 ) at Objects/typeobject.c:1292 # 1292 mro = a->tp_mro; # (gdb) bt # #0 0x08108825 in PyType_IsSubtype (a=0xdbdbdbdb, b=0x830f1a0 ) at Objects/typeobject.c:1292 # #1 0x080f22d6 in do_richcompare (v=1337, w=, op=2) at Objects/object.c:643 # #2 0x080f263d in PyObject_RichCompare (v=1337, w=, op=2) at Objects/object.c:701 # #3 0x080f26ce in PyObject_RichCompareBool (v=1337, w=, op=2) at Objects/object.c:723 # #4 0x080df7b5 in lookdict (mp=0x405c8b34, key=, hash=1337, value_addr=0xbfc40200) # at Objects/dictobject.c:485 # #5 0x080e145d in PyDict_GetItem (op=, key=) at Objects/dictobject.c:1095 # #6 0x405bf6f9 in encoder_listencode_dict (s=0x405b23fc, acc=0xbfc4038c, dct=, indent_level=0) # # Deleting the object in __hash__() method triggers an use after free in PyType_IsSubtype. import json as j class D(dict): def keys(self): global L return L class X: def __del__(self): print("__del__ X") def __hash__(self): global L print("__hash__ X") del L[0] return 1337 def __lt__(self, o): return 0 L = [X() for i in range(1122)] d = D() d[1337]="true.dat" s = j.dumps(d, sort_keys=True) print(s)