Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df6b544

Browse files
committed
Issue #24913: Fix overrun error in deque.index().
Reported by John Leitch and Bryce Darling, patch by Raymond Hettinger.
1 parent b3d5313 commit df6b544

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_deque.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ def test_index(self):
289289
else:
290290
self.assertEqual(d.index(element, start, stop), target)
291291

292+
def test_insert_bug_24913(self):
293+
d = deque('A' * 3)
294+
with self.assertRaises(ValueError):
295+
i = d.index("Hello world", 0, 4)
296+
292297
def test_insert(self):
293298
# Test to make sure insert behaves like lists
294299
elements = 'ABCDEFGHI'

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Core and Builtins
1515
Library
1616
-------
1717

18+
- Issue #24913: Fix overrun error in deque.index().
19+
Found by John Leitch and Bryce Darling.
20+
1821

1922
What's New in Python 3.5.0 release candidate 2?
2023
===============================================

Modules/_collectionsmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,8 @@ deque_index(dequeobject *deque, PyObject *args)
924924
if (stop < 0)
925925
stop = 0;
926926
}
927+
if (stop > Py_SIZE(deque))
928+
stop = Py_SIZE(deque);
927929

928930
for (i=0 ; i<stop ; i++) {
929931
if (i >= start) {

0 commit comments

Comments
 (0)