aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-02-14 18:21:12 +0100
committerMichał Górny <mgorny@gentoo.org>2024-04-10 10:42:27 +0200
commit589562ca756ff61fea46d99544114e55d38cb5b1 (patch)
tree35236f1a9e1709340da87dd21bcdfb8ea43946db
parentPrevent tests from detecting our fake tzdata package (diff)
downloadcpython-gentoo-3.10.14_p1.tar.gz
cpython-gentoo-3.10.14_p1.tar.bz2
cpython-gentoo-3.10.14_p1.zip
[3.11] gh-115243: Fix crash in deque.index() when the deque is concurrently modified (GH-115247) (GH-115466)gentoo-3.10.14_p1
(cherry picked from commit 671360161f0b7a5ff4c1d062e570962e851b4bde) Co-authored-by: kcatss <kcats9731@gmail.com>
-rw-r--r--Lib/test/test_deque.py6
-rw-r--r--Modules/_collectionsmodule.c3
2 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index 7886bbfea1f..c0965df59de 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -165,7 +165,7 @@ class TestBasic(unittest.TestCase):
with self.assertRaises(RuntimeError):
n in d
- def test_contains_count_stop_crashes(self):
+ def test_contains_count_index_stop_crashes(self):
class A:
def __eq__(self, other):
d.clear()
@@ -177,6 +177,10 @@ class TestBasic(unittest.TestCase):
with self.assertRaises(RuntimeError):
_ = d.count(3)
+ d = deque([A()])
+ with self.assertRaises(RuntimeError):
+ d.index(0)
+
def test_extend(self):
d = deque('a')
self.assertRaises(TypeError, d.extend, 1)
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index eff03c789ed..34854a104f2 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1088,8 +1088,9 @@ deque_index(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
n = stop - i;
while (--n >= 0) {
CHECK_NOT_END(b);
- item = b->data[index];
+ item = Py_NewRef(b->data[index]);
cmp = PyObject_RichCompareBool(item, v, Py_EQ);
+ Py_DECREF(item);
if (cmp > 0)
return PyLong_FromSsize_t(stop - n - 1);
if (cmp < 0)