summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorGregory Lee <grlee77@gmail.com>2021-06-24 08:37:01 -0400
committerGregory Lee <grlee77@gmail.com>2021-06-24 08:40:31 -0400
commitbe09bb6ba4d27fbd1f667d34bb2f11cccb446d65 (patch)
treebdfe742f34bf18e3c43f1daa5b70b4fc857bb89c /numpy/core/src
parenta79a913efd9bd7b7d8f8fc8619768dd2b30067f7 (diff)
downloadnumpy-be09bb6ba4d27fbd1f667d34bb2f11cccb446d65.tar.gz
BUG: protect against access an attribute of a NULL pointer
Have PyArray_GetCastSafety return -1 if from is NULL
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/multiarray/convert_datatype.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c
index d197a4bea..716e5dd3d 100644
--- a/numpy/core/src/multiarray/convert_datatype.c
+++ b/numpy/core/src/multiarray/convert_datatype.c
@@ -417,6 +417,9 @@ PyArray_GetCastSafety(
if (to != NULL) {
to_dtype = NPY_DTYPE(to);
}
+ if (from == NULL) {
+ return -1;
+ }
PyObject *meth = PyArray_GetCastingImpl(NPY_DTYPE(from), to_dtype);
if (meth == NULL) {
return -1;
@@ -3293,8 +3296,10 @@ void_to_void_resolve_descriptors(
casting = NPY_NO_CASTING | _NPY_CAST_IS_VIEW;
}
}
- NPY_CASTING field_casting = PyArray_GetCastSafety(
- given_descrs[0]->subarray->base, given_descrs[1]->subarray->base, NULL);
+
+ PyArray_Descr *from_base = (from_sub == NULL) ? NULL : from_sub->base;
+ PyArray_Descr *to_base = (to_sub == NULL) ? NULL : to_sub->base;
+ NPY_CASTING field_casting = PyArray_GetCastSafety(from_base, to_base, NULL);
if (field_casting < 0) {
return -1;
}