summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorBruce Merry <bmerry@ska.ac.za>2019-06-04 16:32:38 +0200
committerBruce Merry <bmerry@ska.ac.za>2019-06-04 16:32:38 +0200
commit5a967c9d61f7c2ecce4e215065731a7ab2832574 (patch)
treed0e0c849ec56b018d0cd5d37d5973d9d935efe6e /numpy
parentafc69816fd2aedf513d4f4e497f28d68e0b2b3d5 (diff)
downloadnumpy-5a967c9d61f7c2ecce4e215065731a7ab2832574.tar.gz
BUG: Fix use-after-free in boolean indexing
The index array is decrefed before extracting the shape to construct the `indices` array. If the caller does not hold a reference (which happens when the caller passed a list from which a temporary array was constructed, for example), this leads to a use-after-free. Closes #13714.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/mapping.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c
index 10206c03e..7c63087ff 100644
--- a/numpy/core/src/multiarray/mapping.c
+++ b/numpy/core/src/multiarray/mapping.c
@@ -611,9 +611,9 @@ prepare_index(PyArrayObject *self, PyObject *index,
/* Convert the boolean array into multiple integer ones */
n = _nonzero_indices((PyObject *)arr, nonzero_result);
- Py_DECREF(arr);
if (n < 0) {
+ Py_DECREF(arr);
goto failed_building_indices;
}
@@ -624,6 +624,7 @@ prepare_index(PyArrayObject *self, PyObject *index,
for (i=0; i < n; i++) {
Py_DECREF(nonzero_result[i]);
}
+ Py_DECREF(arr);
goto failed_building_indices;
}
@@ -637,6 +638,7 @@ prepare_index(PyArrayObject *self, PyObject *index,
used_ndim += 1;
curr_idx += 1;
}
+ Py_DECREF(arr);
/* All added indices have 1 dimension */
if (fancy_ndim < 1) {