summaryrefslogtreecommitdiffstats
path: root/Lib/test/crashers/dictresize_attack.py
blob: 1895791387f25f1c8edc035dd23605effff6308c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# http://www.python.org/sf/1456209

# A dictresize() attack.  If oldtable == mp->ma_smalltable then pure
# Python code can mangle with mp->ma_smalltable while it is being walked
# over.

class X(object):

    def __hash__(self):
        return 5

    def __eq__(self, other):
        if resizing:
            d.clear()
        return False


d = {}

resizing = False

d[X()] = 1
d[X()] = 2
d[X()] = 3
d[X()] = 4
d[X()] = 5

# now trigger a resize
resizing = True
d[9] = 6

# ^^^ I get Segmentation fault or Illegal instruction here.