diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2022-01-12 16:13:44 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-12 16:13:44 -0600 |
commit | fdcb2e4a2260d1e884101327b516a5d5bc1e1de2 (patch) | |
tree | fcaf04bddbe47a470534190b47a8b34118b303f9 | |
parent | 74f9591b83c13b9cc30626be8e06fef871c6e7a6 (diff) | |
parent | 9f1c1e067f49e5a31abb65bd5c68882749ff3c34 (diff) | |
download | numpy-maintenance/1.19.x.tar.gz |
Merge pull request #20801 from tkilias/backport-18989maintenance/1.19.x
BUG: fix potential buffer overflow, backport to 1.19.* (#18939)
-rw-r--r-- | numpy/core/src/multiarray/ctors.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index 851244adf..4f88899e9 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -933,6 +933,14 @@ PyArray_NewFromDescr_int( int i; npy_intp nbytes; + if ((unsigned int)nd > (unsigned int)NPY_MAXDIMS) { + PyErr_Format(PyExc_ValueError, + "number of dimensions must be within [0, %d]", + NPY_MAXDIMS); + Py_DECREF(descr); + return NULL; + } + if (descr->subarray) { PyObject *ret; npy_intp newdims[2*NPY_MAXDIMS]; @@ -952,13 +960,6 @@ PyArray_NewFromDescr_int( return ret; } - if ((unsigned int)nd > (unsigned int)NPY_MAXDIMS) { - PyErr_Format(PyExc_ValueError, - "number of dimensions must be within [0, %d]", - NPY_MAXDIMS); - Py_DECREF(descr); - return NULL; - } /* Check datatype element size */ nbytes = descr->elsize; |