From df6b544ff6f342e8a64056e627867a70413bfdb0 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Thu, 3 Sep 2015 10:15:03 -0700 Subject: [PATCH] Issue #24913: Fix overrun error in deque.index(). Reported by John Leitch and Bryce Darling, patch by Raymond Hettinger. --- Lib/test/test_deque.py | 5 +++++ Misc/NEWS | 3 +++ Modules/_collectionsmodule.c | 2 ++ 3 files changed, 10 insertions(+) diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index b8585096841..87187161ab3 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -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' diff --git a/Misc/NEWS b/Misc/NEWS index 8f34c5479e6..b1beeec473d 100644 --- 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? =============================================== diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 830c5b83ebc..3856d83fb4e 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -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= start) {