[Python-checkins] cpython (merge 3.4 -> 3.5): Issue #25021: Merge 3.4 to 3.5
kristjan.jonsson
python-checkins at python.org
Sat Sep 12 18:42:17 CEST 2015
https://hg.python.org/cpython/rev/ca628ccec846
changeset: 97946:ca628ccec846
branch: 3.5
parent: 97940:cdd1679e666d
parent: 97945:4f85b6228697
user: Kristján Valur Jónsson <sweskman at gmail.com>
date: Sat Sep 12 16:34:33 2015 +0000
summary:
Issue #25021: Merge 3.4 to 3.5
files:
Lib/test/test_itertools.py | 10 ++++++++++
Modules/itertoolsmodule.c | 12 ++++++++++--
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -985,6 +985,16 @@
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
self.pickletest(proto, product(*args))
+ def test_product_issue_25021(self):
+ # test that indices are properly clamped to the length of the tuples
+ p = product((1, 2),(3,))
+ p.__setstate__((0, 0x1000)) # will access tuple element 1 if not clamped
+ self.assertEqual(next(p), (2, 3))
+ # test that empty tuple in the list will result in an immediate StopIteration
+ p = product((1, 2), (), (3,))
+ p.__setstate__((0, 0, 0x1000)) # will access tuple element 1 if not clamped
+ self.assertRaises(StopIteration, next, p)
+
def test_repeat(self):
self.assertEqual(list(repeat(object='a', times=3)), ['a', 'a', 'a'])
self.assertEqual(lzip(range(3),repeat('a')),
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -2236,13 +2236,21 @@
{
PyObject* indexObject = PyTuple_GET_ITEM(state, i);
Py_ssize_t index = PyLong_AsSsize_t(indexObject);
+ PyObject* pool;
+ Py_ssize_t poolsize;
if (index < 0 && PyErr_Occurred())
return NULL; /* not an integer */
+ pool = PyTuple_GET_ITEM(lz->pools, i);
+ poolsize = PyTuple_GET_SIZE(pool);
+ if (poolsize == 0) {
+ lz->stopped = 1;
+ Py_RETURN_NONE;
+ }
/* clamp the index */
if (index < 0)
index = 0;
- else if (index > n-1)
- index = n-1;
+ else if (index > poolsize-1)
+ index = poolsize-1;
lz->indices[i] = index;
}
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list