[Python-checkins] bpo-38202: Fix a crash in dict_view & non-itearble. (GH-16241)

Serhiy Storchaka webhook-mailer at python.org
Sun Oct 13 07:49:09 EDT 2019


https://github.com/python/cpython/commit/b16e382c446d76ede22780b15c75f43c5f132e25
commit: b16e382c446d76ede22780b15c75f43c5f132e25
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2019年10月13日T14:49:05+03:00
summary:
bpo-38202: Fix a crash in dict_view & non-itearble. (GH-16241)
files:
M Lib/test/test_dictviews.py
M Objects/dictobject.c
diff --git a/Lib/test/test_dictviews.py b/Lib/test/test_dictviews.py
index 8410e8b5c44d4..be271bebaaf1f 100644
--- a/Lib/test/test_dictviews.py
+++ b/Lib/test/test_dictviews.py
@@ -227,6 +227,25 @@ def test_set_operations_with_iterator(self):
 self.assertEqual(items | iter([(1, 2)]), {(1, 2), (3, 4)})
 self.assertEqual(items - iter([(1, 2)]), {(3, 4)})
 
+ def test_set_operations_with_noniterable(self):
+ with self.assertRaises(TypeError):
+ {}.keys() & 1
+ with self.assertRaises(TypeError):
+ {}.keys() | 1
+ with self.assertRaises(TypeError):
+ {}.keys() ^ 1
+ with self.assertRaises(TypeError):
+ {}.keys() - 1
+
+ with self.assertRaises(TypeError):
+ {}.items() & 1
+ with self.assertRaises(TypeError):
+ {}.items() | 1
+ with self.assertRaises(TypeError):
+ {}.items() ^ 1
+ with self.assertRaises(TypeError):
+ {}.items() - 1
+
 def test_recursive_repr(self):
 d = {}
 d[42] = d.values()
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index b496350d47093..64876e05191e2 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -4227,6 +4227,10 @@ _PyDictView_Intersect(PyObject* self, PyObject *other)
 return NULL;
 
 it = PyObject_GetIter(other);
+ if (it == NULL) {
+ Py_DECREF(result);
+ return NULL;
+ }
 
 if (PyDictKeys_Check(self)) {
 dict_contains = dictkeys_contains;


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /