diff options
author | Simon Gibbons <simongibbons@gmail.com> | 2016-03-29 10:43:26 +0100 |
---|---|---|
committer | Simon Gibbons <simongibbons@gmail.com> | 2016-03-29 13:40:56 +0100 |
commit | 163a6f96e81eed44c9c58d54615b5bcbcad67bec (patch) | |
tree | c1465e50c7b3c96aa39198db90c8ba2897a53af9 /numpy/core | |
parent | 75c5af30d7137fd308227028ebdee31dbe841e7f (diff) | |
download | numpy-163a6f96e81eed44c9c58d54615b5bcbcad67bec.tar.gz |
BUG: Fix segfault in PyArray_OrderConverter
This fixes a bug in PyArray_OrderConverter where
if a unicode string is passed in which cannot
be converted to ASCII then Py_DECREF would
be called on a null pointer.
Fixes #7475
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/multiarray/conversion_utils.c | 7 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 4 |
2 files changed, 11 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c index d7a617875..c016bb8d1 100644 --- a/numpy/core/src/multiarray/conversion_utils.c +++ b/numpy/core/src/multiarray/conversion_utils.c @@ -535,6 +535,13 @@ PyArray_OrderConverter(PyObject *object, NPY_ORDER *val) PyObject *tmp; int ret; tmp = PyUnicode_AsASCIIString(object); + if (tmp == NULL) { + PyErr_SetString(PyExc_ValueError, "Invalid unicode string passed in " + "for the array ordering. " + "Please pass in 'C', 'F', 'A' " + "or 'K' instead"); + return NPY_FAIL; + } ret = PyArray_OrderConverter(tmp, val); Py_DECREF(tmp); return ret; diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 262fbc0c0..deb1f66eb 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -6437,6 +6437,10 @@ class TestUnicodeArrayNonzero(TestCase): a[0] = ' \0 \0' self.assertTrue(a) +def test_orderconverter_with_nonASCII_unicode_ordering(): + # gh-7475 + a = np.arange(5) + assert_raises(ValueError, a.flatten, order=u'\xe2') if __name__ == "__main__": run_module_suite() |