diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-09-19 21:30:19 +0200 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-09-19 21:36:49 +0200 |
commit | 5a14415b0aa8df194b68da840d6a58297e1e03b0 (patch) | |
tree | fd2d62b5107cfbfbf50c54e3482bcf17dbfb80bb | |
parent | 9af50285a7807c67f13b2ede17791a1e693da148 (diff) | |
download | numpy-5a14415b0aa8df194b68da840d6a58297e1e03b0.tar.gz |
BUG: fix out of bound access in unicode argmin/argmax
elsize is in bytes and the pointer of unicode type, so it must divided
by the size.
Closes gh-5082
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index d2532ccf0..c4130353b 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -2991,7 +2991,7 @@ static int memcpy(mp, ip, elsize); *max_ind = 0; for (i = 1; i < n; i++) { - ip += elsize; + ip += elsize / sizeof(@type@); if (@fname@_compare(ip, mp, aip) > 0) { memcpy(mp, ip, elsize); *max_ind = i; @@ -3048,7 +3048,7 @@ static int memcpy(mp, ip, elsize); *min_ind = 0; for(i=1; i<n; i++) { - ip += elsize; + ip += elsize / sizeof(@type@); if (@fname@_compare(mp,ip,aip) > 0) { memcpy(mp, ip, elsize); *min_ind=i; diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index d02821cba..e49f905f9 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -2144,6 +2144,11 @@ class TestArgmax(TestCase): a.argmax(-1, out=out) assert_equal(out, a.argmax(-1)) + def test_argmax_unicode(self): + d = np.zeros(6031, dtype='<U9') + d[5942] = "as" + assert_equal(d.argmax(), 5942) + class TestArgmin(TestCase): @@ -2249,6 +2254,11 @@ class TestArgmin(TestCase): a.argmin(-1, out=out) assert_equal(out, a.argmin(-1)) + def test_argmin_unicode(self): + d = np.ones(6031, dtype='<U9') + d[6001] = "0" + assert_equal(d.argmin(), 6001) + class TestMinMax(TestCase): def test_scalar(self): |