[Python-checkins] cpython (3.5): Issue #24583: Fix crash when set is mutated while being updated.

raymond.hettinger python-checkins at python.org
Thu Jul 16 08:54:18 CEST 2015


https://hg.python.org/cpython/rev/5c3812412b6f
changeset:   96917:5c3812412b6f
branch:      3.5
parent:      96913:fce682a493e7
user:        Raymond Hettinger <python at rcn.com>
date:        Wed Jul 15 23:50:14 2015 -0700
summary:
  Issue #24583: Fix crash when set is mutated while being updated.

files:
  Lib/test/test_set.py |  13 +++++++++++++
  Misc/NEWS            |   2 ++
  Objects/setobject.c  |   3 ++-
  3 files changed, 17 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -1742,6 +1742,19 @@
         s.update(range(100))
         list(si)
 
+    def test_merge_and_mutate(self):
+        class X:
+            def __hash__(self):
+                return hash(0)
+            def __eq__(self, o):
+                other.clear()
+                return False
+
+        other = set()
+        other = {X() for i in range(10)}
+        s = {0}
+        s.update(other)
+
 # Application tests (based on David Eppstein's graph recipes ====================================
 
 def powerset(U):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@
 
 - Issue #24569: Make PEP 448 dictionary evaluation more consistent.
 
+- Issue #24583: Fix crash when set is mutated while being updated.
+
 - Issue #24407: Fix crash when dict is mutated while being updated.
 
 Library
diff --git a/Objects/setobject.c b/Objects/setobject.c
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -600,7 +600,8 @@
     }
 
     /* We can't assure there are no duplicates, so do normal insertions */
-    for (i = 0; i <= other->mask; i++, other_entry++) {
+    for (i = 0; i <= other->mask; i++) {
+        other_entry = &other->table[i];
         key = other_entry->key;
         if (key != NULL && key != dummy) {
             Py_INCREF(key);

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list