summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorKristján Valur Jónsson <sweskman@gmail.com>2015-09-12 15:20:54 (GMT)
committerKristján Valur Jónsson <sweskman@gmail.com>2015-09-12 15:20:54 (GMT)
commit102764a1f6927955b9a907005ffd07216ebe1d96 (patch)
tree32b516565947c7d9ff51ae5c40abc14e8bac7003 /Modules
parenta82f77fb00ca3bd3eb27a6a5d77a19eadcf0ba31 (diff)
downloadcpython-102764a1f6927955b9a907005ffd07216ebe1d96.zip
cpython-102764a1f6927955b9a907005ffd07216ebe1d96.tar.gz
cpython-102764a1f6927955b9a907005ffd07216ebe1d96.tar.bz2
Issue #25021: Correctly make sure that product.__setstate__ does not access
invalid memory.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/itertoolsmodule.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index a9e5709..57a398f 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -2205,13 +2205,21 @@ product_setstate(productobject *lz, PyObject *state)
{
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;
}