]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #24913: Fix overrun error in deque.index().
authorBrett Cannon <brett@python.org>
Thu, 3 Sep 2015 17:15:03 +0000 (10:15 -0700)
committerBrett Cannon <brett@python.org>
Thu, 3 Sep 2015 17:15:03 +0000 (10:15 -0700)
Reported by John Leitch and Bryce Darling, patch by Raymond Hettinger.

Lib/test/test_deque.py
Misc/NEWS
Modules/_collectionsmodule.c

index b858509684129c70dba3a20922604c7a1fdfc93d..87187161ab30d84bbc2febf7cfa31bec431bd339 100644 (file)
@@ -289,6 +289,11 @@ class TestBasic(unittest.TestCase):
                     else:
                         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):
         # Test to make sure insert behaves like lists
         elements = 'ABCDEFGHI'
index 8f34c5479e6c9390c5963aaee3208ae2d35a8efa..b1beeec473d4f3ad88c01cc6b669e96cdbb039da 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,9 @@ Core and Builtins
 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?
 ===============================================
index 830c5b83ebcb925a2f7a66875dded11683a8b599..3856d83fb4e17fc3ee6744f06900e8b21fff26b8 100644 (file)
@@ -924,6 +924,8 @@ deque_index(dequeobject *deque, PyObject *args)
         if (stop < 0)
             stop = 0;
     }
+    if (stop > Py_SIZE(deque))
+        stop = Py_SIZE(deque);
 
     for (i=0 ; i<stop ; i++) {
         if (i >= start) {