Skip to content

Commit

Permalink
Merge pull request numpy#18989 from yetanothercheer/numpygh-18939-pot…
Browse files Browse the repository at this point in the history
…ential_buffer_overflow

BUG: fix potential buffer overflow(numpy#18939)
  • Loading branch information
charris authored May 11, 2021
2 parents 938fe1f + 16f7824 commit ae317fd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions numpy/core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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)) {
Expand Down

0 comments on commit ae317fd

Please sign in to comment.