Debian Codegraph @

cpython27/Lib/test/crashers/gc_has_finalizer.py

raw symbols SCIP
1 """
2 The gc module can still invoke arbitrary Python code and crash.
3 This is an attack against _PyInstance_Lookup(), which is documented
4 as follows:
5
6 The point of this routine is that it never calls arbitrary Python
7 code, so is always "safe": all it does is dict lookups.
8
9 But of course dict lookups can call arbitrary Python code.
10 The following code causes mutation of the object graph during
11 the call to has_finalizer() in gcmodule.c, and that might
12 segfault.
13 """
14
15 import gc
16
17
18 class A:
19 def __hash__(self):
20 return hash("__del__")
21 def __eq__(self, other):
22 del self.other
23 return False
24
25 a = A()
26 b = A()
27
28 a.__dict__[b] = 'A'
29
30 a.other = b
31 b.other = a
32
33 gc.collect()
34 del a, b
35
36 gc.collect()