diff options
| author | Benjamin Peterson <benjamin@python.org> | 2015-02-02 02:36:01 (GMT) |
|---|---|---|
| committer | Benjamin Peterson <benjamin@python.org> | 2015-02-02 02:36:01 (GMT) |
| commit | 5d0bb852a25d010cc1aacf661d26a6bae1c8bf1a (patch) | |
| tree | 54d6a3f6338a8fec9015cf708f12007b4007e4bb /Modules | |
| parent | 38d9772622fa13f7dc1033cd29bad1b15a31c8b4 (diff) | |
| parent | c468b537cd227ce5484500a8f8ea7e932eabc7d5 (diff) | |
| download | cpython-5d0bb852a25d010cc1aacf661d26a6bae1c8bf1a.zip cpython-5d0bb852a25d010cc1aacf661d26a6bae1c8bf1a.tar.gz cpython-5d0bb852a25d010cc1aacf661d26a6bae1c8bf1a.tar.bz2 | |
merge 3.4 (#23364, #23363)
Diffstat (limited to 'Modules')
| -rw-r--r-- | Modules/itertoolsmodule.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 610799f..1e0d49a 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -2017,8 +2017,17 @@ product_new(PyTypeObject *type, PyObject *args, PyObject *kwds) } } - assert(PyTuple_Check(args)); - nargs = (repeat == 0) ? 0 : PyTuple_GET_SIZE(args); + assert(PyTuple_CheckExact(args)); + if (repeat == 0) { + nargs = 0; + } else { + nargs = PyTuple_GET_SIZE(args); + if (repeat > PY_SSIZE_T_MAX/sizeof(Py_ssize_t) || + nargs > PY_SSIZE_T_MAX/(repeat * sizeof(Py_ssize_t))) { + PyErr_SetString(PyExc_OverflowError, "repeat argument too large"); + return NULL; + } + } npools = nargs * repeat; indices = PyMem_Malloc(npools * sizeof(Py_ssize_t)); @@ -3049,6 +3058,11 @@ permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds) goto error; } + if (n > PY_SSIZE_T_MAX/sizeof(Py_ssize_t) || + r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) { + PyErr_SetString(PyExc_OverflowError, "parameters too large"); + goto error; + } indices = PyMem_Malloc(n * sizeof(Py_ssize_t)); cycles = PyMem_Malloc(r * sizeof(Py_ssize_t)); if (indices == NULL || cycles == NULL) { |
