Commit b9f9094e authored by Brett Cannon's avatar Brett Cannon

Issue #24913: Fix overrun error in deque.index().

Reported by John Leitch and Bryce Darling, patch by Raymond Hettinger.
parent 24d30c35
...@@ -289,6 +289,11 @@ class TestBasic(unittest.TestCase): ...@@ -289,6 +289,11 @@ class TestBasic(unittest.TestCase):
else: else:
self.assertEqual(d.index(element, start, stop), target) self.assertEqual(d.index(element, start, stop), target)
def test_insert_bug_24913(self):
d = deque('A' * 3)
with self.assertRaises(ValueError):
i = d.index("Hello world", 0, 4)
def test_insert(self): def test_insert(self):
# Test to make sure insert behaves like lists # Test to make sure insert behaves like lists
elements = 'ABCDEFGHI' elements = 'ABCDEFGHI'
......
...@@ -15,6 +15,9 @@ Core and Builtins ...@@ -15,6 +15,9 @@ Core and Builtins
Library Library
------- -------
- Issue #24913: Fix overrun error in deque.index().
Found by John Leitch and Bryce Darling.
What's New in Python 3.5.0 release candidate 2? What's New in Python 3.5.0 release candidate 2?
=============================================== ===============================================
......
...@@ -924,6 +924,8 @@ deque_index(dequeobject *deque, PyObject *args) ...@@ -924,6 +924,8 @@ deque_index(dequeobject *deque, PyObject *args)
if (stop < 0) if (stop < 0)
stop = 0; stop = 0;
} }
if (stop > Py_SIZE(deque))
stop = Py_SIZE(deque);
for (i=0 ; i<stop ; i++) { for (i=0 ; i<stop ; i++) {
if (i >= start) { if (i >= start) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment