Skip to content

Commit 785f5e6

Browse files
authored
bpo-40489: Add test case for dict contain use after free (GH-19906)
1 parent caa3ef2 commit 785f5e6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Lib/test/test_dict.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,19 @@ def __eq__(self, other):
13241324
d = {0: set()}
13251325
(0, X()) in d.items()
13261326

1327+
def test_dict_contain_use_after_free(self):
1328+
# bpo-40489
1329+
class S(str):
1330+
def __eq__(self, other):
1331+
d.clear()
1332+
return NotImplemented
1333+
1334+
def __hash__(self):
1335+
return hash('test')
1336+
1337+
d = {S(): 'value'}
1338+
self.assertFalse('test' in d)
1339+
13271340
def test_init_use_after_free(self):
13281341
class X:
13291342
def __hash__(self):

0 commit comments

Comments
 (0)