summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan van der Walt <stefan@sun.ac.za>2007-11-18 20:49:47 +0000
committerStefan van der Walt <stefan@sun.ac.za>2007-11-18 20:49:47 +0000
commit7254dd7da0ce26f83b667dcff1fb3b545fb47899 (patch)
treea47b7f77456284fea58642db081bd6fd2a340b59
parent4ae613d0b53ef17aced122ce8a89274c1ee1ac8e (diff)
downloadnumpy-7254dd7da0ce26f83b667dcff1fb3b545fb47899.tar.gz
Fix indexing with booleans (patch by Achim Gaedke). Closes #614.
-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()