summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2021-05-11 13:39:32 -0600
committerGitHub <noreply@github.com>2021-05-11 13:39:32 -0600
commitae317fd9ff3e79c0eac357d723bfc29cbd625f2e (patch)
tree50ca8bbc8162fe71ed1c7d5beb50475caf49397e /numpy
parent938fe1f871e22b8f5556b946135fa700e5ebcce1 (diff)
parent16f7824b4d935b6aee98298ca4123d57174a6f2e (diff)
downloadnumpy-ae317fd9ff3e79c0eac357d723bfc29cbd625f2e.tar.gz
Merge pull request #18989 from yetanothercheer/gh-18939-potential_buffer_overflow
BUG: fix potential buffer overflow(#18939)
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/ctors.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 57cfa1e36..7907fb930 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -668,6 +668,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];
@@ -687,14 +695,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;
if (PyDataType_ISUNSIZED(descr)) {