Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory access out of bounds in numpy + chrome 89 #1474

Merged
merged 23 commits into from
Apr 17, 2021
Merged
Prev Previous commit
Next Next commit
Fix commented original function
  • Loading branch information
Hood committed Apr 16, 2021
commit 24e86981a9b52b61ad0852fc19b4c529a6ca5a75
65 changes: 33 additions & 32 deletions src/core/numpy_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,40 +226,41 @@ PyArray_Broadcast(PyArrayMultiIterObject *mit)
PyArrayIterObject *it;
PyArrayIterObject **it_ptr;

/* Discover the broadcast number of dimensions */
for (i = 0, nd = 0; i < mit->numiter; i++) {
nd = PyArray_MAX(nd, PyArray_NDIM(mit->iters[i]->ao));
}
mit->nd = nd;
/ * Discover the broadcast number of dimensions * /
for (i = 0, nd = 0; i < mit->numiter; i++) {
nd = PyArray_MAX(nd, PyArray_NDIM(mit->iters[i]->ao));
}
mit->nd = nd;

/ *Discover the broadcast shape in each dimension* / for (i = 0; i < nd; i++)
{
mit->dimensions[i] = 1;
}
/ * Discover the broadcast shape in each dimension * /
for (i = 0; i < nd; i++) {
mit->dimensions[i] = 1;
}

for (j = 0; j < mit->numiter; j++) {
it = mit->iters[j];
for (i = 0; i < nd; i++) {
/ * This prepends 1 to shapes not already equal to nd* / k =
i + PyArray_NDIM(it->ao) - nd;
if (k >= 0) {
tmp = PyArray_DIMS(it->ao)[k];
if (tmp == 1) {
continue;
}
if (mit->dimensions[i] == 1) {
mit->dimensions[i] = tmp;
} else if (mit->dimensions[i] != tmp) {
PyErr_SetString(PyExc_ValueError,
"shape mismatch: objects"
" cannot be broadcast"
" to a single shape");
return -1;
}
for (j = 0; j < mit->numiter; j++) {
it = mit->iters[j];
for (i = 0; i < nd; i++) {
/ * This prepends 1 to shapes not already equal to nd * /
k = i + PyArray_NDIM(it->ao) - nd;
if (k >= 0) {
tmp = PyArray_DIMS(it->ao)[k];
if (tmp == 1) {
continue;
}
if (mit->dimensions[i] == 1) {
mit->dimensions[i] = tmp;
}
else if (mit->dimensions[i] != tmp) {
PyErr_SetString(PyExc_ValueError,
"shape mismatch: objects" \
" cannot be broadcast" \
" to a single shape");
return -1;
}
}
}
}
}
}

// Rest of function skipped
// Rest of function skipped
}
* /
*/