Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0e07ebd

Browse filesBrowse files
[3.11] gh-115243: Fix crash in deque.index() when the deque is concurrently modified (GH-115247) (GH-115466)
(cherry picked from commit 6713601) Co-authored-by: kcatss <kcats9731@gmail.com>
1 parent 7b94f47 commit 0e07ebd
Copy full SHA for 0e07ebd

File tree

3 files changed

+8
-2
lines changed
Filter options

3 files changed

+8
-2
lines changed

‎Lib/test/test_deque.py

Copy file name to clipboardExpand all lines: Lib/test/test_deque.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_contains(self):
166166
with self.assertRaises(RuntimeError):
167167
n in d
168168

169-
def test_contains_count_stop_crashes(self):
169+
def test_contains_count_index_stop_crashes(self):
170170
class A:
171171
def __eq__(self, other):
172172
d.clear()
@@ -178,6 +178,10 @@ def __eq__(self, other):
178178
with self.assertRaises(RuntimeError):
179179
_ = d.count(3)
180180

181+
d = deque([A()])
182+
with self.assertRaises(RuntimeError):
183+
d.index(0)
184+
181185
def test_extend(self):
182186
d = deque('a')
183187
self.assertRaises(TypeError, d.extend, 1)
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix possible crashes in :meth:`collections.deque.index` when the deque is concurrently modified.

‎Modules/_collectionsmodule.c

Copy file name to clipboardExpand all lines: Modules/_collectionsmodule.c
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,9 @@ deque_index(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
10841084
n = stop - i;
10851085
while (--n >= 0) {
10861086
CHECK_NOT_END(b);
1087-
item = b->data[index];
1087+
item = Py_NewRef(b->data[index]);
10881088
cmp = PyObject_RichCompareBool(item, v, Py_EQ);
1089+
Py_DECREF(item);
10891090
if (cmp > 0)
10901091
return PyLong_FromSsize_t(stop - n - 1);
10911092
if (cmp < 0)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.