diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-10-09 11:16:26 -0400 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-10-09 11:16:26 -0400 |
commit | 455fa0a314b7f7edd0c8554b12a65267ff1e2e5b (patch) | |
tree | a4db0395d8674c1e3c4119f0edccf72307b34e49 /Modules/arraymodule.c | |
parent | b29614e047110f4d9af993a6cdec4e3fb7ef9738 (diff) | |
parent | 831893a68ec7114c1fc9c8e36b9159f5c1db50c7 (diff) | |
download | cpython-git-455fa0a314b7f7edd0c8554b12a65267ff1e2e5b.tar.gz |
merge heads
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r-- | Modules/arraymodule.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 04eb67c790..3f5aa8b361 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -483,11 +483,11 @@ newarrayobject(PyTypeObject *type, Py_ssize_t size, struct arraydescr *descr) return NULL; } - nbytes = size * descr->itemsize; /* Check for overflow */ - if (nbytes / descr->itemsize != (size_t)size) { + if (size > PY_SSIZE_T_MAX / descr->itemsize) { return PyErr_NoMemory(); } + nbytes = size * descr->itemsize; op = (arrayobject *) type->tp_alloc(type, 0); if (op == NULL) { return NULL; @@ -1251,11 +1251,15 @@ array_fromfile(arrayobject *self, PyObject *args) if (!PyArg_ParseTuple(args, "On:fromfile", &f, &n)) return NULL; - nbytes = n * itemsize; - if (nbytes < 0 || nbytes/itemsize != n) { + if (n < 0) { + PyErr_SetString(PyExc_ValueError, "negative count"); + return NULL; + } + if (n > PY_SSIZE_T_MAX / itemsize) { PyErr_NoMemory(); return NULL; } + nbytes = n * itemsize; b = _PyObject_CallMethodId(f, &PyId_read, "n", nbytes); if (b == NULL) |