summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/arrayobject.c7
-rw-r--r--numpy/core/tests/test_regression.py7
2 files changed, 14 insertions, 0 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 2847b7796..e84ba56fc 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -9336,7 +9336,14 @@ iter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,
"boolean index array should have 1 dimension");
return -1;
}
+
index = ind->dimensions[0];
+ if (index > self->size) {
+ PyErr_SetString(PyExc_ValueError,
+ "boolean index array has too many values");
+ return -1;
+ }
+
strides = ind->strides[0];
dptr = ind->data;
PyArray_ITER_RESET(self);
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index fd81b231f..661ef5531 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -756,5 +756,12 @@ class TestRegression(NumpyTestCase):
assert_equal(N.arange(0.5,dtype=dt).dtype,dt)
assert_equal(N.arange(5,dtype=dt).dtype,dt)
+ def check_bool_indexing_invalid_nr_elements(self, level=rlevel):
+ s = N.ones(10,dtype=float)
+ x = N.array((15,),dtype=float)
+ def ia(x,s): x[(s>0)]=1.0
+ self.failUnlessRaises(ValueError,ia,x,s)
+
+
if __name__ == "__main__":
NumpyTest().run()