mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
Merge de4dbb4b7b into f9704f1d84
This commit is contained in:
commit
47db12d2af
3 changed files with 32 additions and 0 deletions
|
|
@ -675,6 +675,35 @@ class TestSet(TestJointOps, unittest.TestCase):
|
|||
with self.assertRaises(KeyError):
|
||||
myset.discard(elem2)
|
||||
|
||||
def test_set_add_to_dummy_slot(self):
|
||||
# gh-141805
|
||||
tasks = set()
|
||||
|
||||
class Dummy:
|
||||
def __hash__(self):
|
||||
return 0
|
||||
|
||||
class CorruptTrigger:
|
||||
triggered = False
|
||||
|
||||
def __hash__(self):
|
||||
return 0
|
||||
|
||||
def __eq__(self, value):
|
||||
if not self.triggered:
|
||||
self.triggered = True
|
||||
tasks.add(self)
|
||||
return False
|
||||
|
||||
tasks.add(Dummy())
|
||||
tasks.add(Dummy())
|
||||
tasks.pop()
|
||||
self.assertEqual(len(tasks), 1)
|
||||
tasks.add(CorruptTrigger())
|
||||
self.assertEqual(len(tasks), 2)
|
||||
# cover the case in gh-141805 that triggers segfault
|
||||
repr(tasks)
|
||||
|
||||
|
||||
class SetSubclass(set):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Fix set corruption due to invalid length calculation when set additions occur
|
||||
in the element comparison (:meth:`object.__eq__`) methods.
|
||||
|
|
@ -298,6 +298,7 @@ set_add_entry_takeref(PySetObject *so, PyObject *key, Py_hash_t hash)
|
|||
else if (entry->hash == -1) {
|
||||
assert (entry->key == dummy);
|
||||
freeslot = entry;
|
||||
goto found_unused_or_dummy;
|
||||
}
|
||||
entry++;
|
||||
} while (probes--);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue