Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca397d8

Browse files
committed
Merge pull request #4839 from juliantaylor/buffer-overflow
BUG: fix buffer overflow in data array of ldexp and frexp
2 parents 94417e4 + 4b8c9fd commit ca397d8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

numpy/core/src/umath/umathmodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,6 @@ static PyUFuncGenericFunction frexp_functions[] = {
214214
#endif
215215
};
216216

217-
static void * blank3_data[] = { (void *)NULL, (void *)NULL, (void *)NULL};
218-
static void * blank6_data[] = { (void *)NULL, (void *)NULL, (void *)NULL,
219-
(void *)NULL, (void *)NULL, (void *)NULL};
220217
static char frexp_signatures[] = {
221218
#ifdef HAVE_FREXPF
222219
NPY_HALF, NPY_HALF, NPY_INT,
@@ -227,6 +224,7 @@ static char frexp_signatures[] = {
227224
,NPY_LONGDOUBLE, NPY_LONGDOUBLE, NPY_INT
228225
#endif
229226
};
227+
static void * blank_data[12];
230228

231229
#if NPY_SIZEOF_LONG == NPY_SIZEOF_INT
232230
#define LDEXP_LONG(typ) typ##_ldexp
@@ -357,14 +355,16 @@ InitOtherOperators(PyObject *dictionary) {
357355
int num;
358356

359357
num = sizeof(frexp_functions) / sizeof(frexp_functions[0]);
360-
f = PyUFunc_FromFuncAndData(frexp_functions, blank3_data,
358+
assert(sizeof(blank_data) / sizeof(blank_data[0]) >= num);
359+
f = PyUFunc_FromFuncAndData(frexp_functions, blank_data,
361360
frexp_signatures, num,
362361
1, 2, PyUFunc_None, "frexp", frdoc, 0);
363362
PyDict_SetItemString(dictionary, "frexp", f);
364363
Py_DECREF(f);
365364

366365
num = sizeof(ldexp_functions) / sizeof(ldexp_functions[0]);
367-
f = PyUFunc_FromFuncAndData(ldexp_functions, blank6_data,
366+
assert(sizeof(blank_data) / sizeof(blank_data[0]) >= num);
367+
f = PyUFunc_FromFuncAndData(ldexp_functions, blank_data,
368368
ldexp_signatures, num,
369369
2, 1, PyUFunc_None, "ldexp", lddoc, 0);
370370
PyDict_SetItemString(dictionary, "ldexp", f);

0 commit comments

Comments
 (0)