diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-12-05 19:04:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-05 19:04:52 (GMT) |
commit | beb834292db54fea129dd073cc822179430cee52 (patch) | |
tree | e4a3383665647e721132b178ca028020a725f384 /Lib/test | |
parent | f6648e229edf07a1e4897244d7d34989dd9ea647 (diff) | |
download | cpython-beb834292db54fea129dd073cc822179430cee52.zip cpython-beb834292db54fea129dd073cc822179430cee52.tar.gz cpython-beb834292db54fea129dd073cc822179430cee52.tar.bz2 |
bpo-27946: Fix possible crash in ElementTree.Element (GH-29915)
Getting an attribute via attrib.get() simultaneously with replacing
the attrib dict can lead to access to deallocated dict.
(cherry picked from commit d15cdb2f32f572ce56d7120135da24b9fdce4c99)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_xml_etree_c.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index e68613b..bec8208 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -169,6 +169,18 @@ class MiscTests(unittest.TestCase): del parser support.gc_collect() + def test_dict_disappearing_during_get_item(self): + # test fix for seg fault reported in issue 27946 + class X: + def __hash__(self): + e.attrib = {} # this frees e->extra->attrib + [{i: i} for i in range(1000)] # exhaust the dict keys cache + return 13 + + e = cET.Element("elem", {1: 2}) + r = e.get(X()) + self.assertIsNone(r) + @unittest.skipUnless(cET, 'requires _elementtree') class TestAliasWorking(unittest.TestCase): |