-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
API,BUG: Fix scalar handling in array-interface allowing NULL pointers #29338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
if (PyArray_SIZE(ret) > 1) { | ||
PyErr_SetString(PyExc_ValueError, | ||
"cannot coerce scalar to array with size > 1"); | ||
Py_DECREF(ret); | ||
goto fail; | ||
} | ||
if (PyArray_SETITEM(ret, PyArray_DATA(ret), origin) < 0) { | ||
if (PyArray_Pack(PyArray_DESCR(ret), PyArray_DATA(ret), origin) < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably doesn't matter in practice, but could matter for new dtypes in principle. It's just the right way now.
return NULL; | ||
} | ||
else if (result == 1) { | ||
Py_DECREF(iface); | ||
Py_DECREF(attr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a plain bug-fix, it could (and maybe should) be backported. In this branch attr
is explicitly still NULL
, since result == 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. This must have been a bug from the GetItemRef
migration. Care to make a backport PR for this?
This fixes the scalar handling in the array-interface and also a bug in the shape handling error path. In theory it breaks code that used NULL to trigger the scalar path, but this path was: 1. Completely undocumented, and 2. correctly triggered by *ommitting* the data field instead. I didn't remove/deprecate the scalar path in this PR, maybe we should. But, I do think we can ignore that theoretical use-case since it is nonsensical. Signed-off-by: Sebastian Berg <sebastianb@nvidia.com>
9ec8b22
to
10af699
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
return NULL; | ||
} | ||
else if (result == 1) { | ||
Py_DECREF(iface); | ||
Py_DECREF(attr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. This must have been a bug from the GetItemRef
migration. Care to make a backport PR for this?
This fixes the scalar handling in the array-interface and also a bug in the shape handling error path.
In theory it breaks code that used NULL to trigger the scalar path, but this path was:
I didn't remove/deprecate the scalar path in this PR, maybe we should. But, I do think we can ignore that theoretical use-case since it is nonsensical.
Closes gh-26037