-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: don't create array with invalid memory in where #8964
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
Conversation
When creating the tuple view of np.where, make sure the arrays point to valid memory when they are empty. Numpy assumes that even empty arrays have valid memory, e.g. in the source stride == 0 assignments. Closes numpygh-8922.
@@ -6619,6 +6619,14 @@ def test_string(self): | |||
assert_equal(np.where(True, a, b), "abcd") | |||
assert_equal(np.where(False, b, a), "abcd") | |||
|
|||
def test_empty_result(self): | |||
# pass empty where result through an assignment which reads the data of | |||
# empty arrays, error detectable with valgrind, see gh-8922 |
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.
Isn't the real bug here that data is being read from an empty array?
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.
arguably yes, but doing so helps finding these bugs
We could also put a |
It seems to be that it should be perfectly legal to invoke Given that it's public API, this patch doesn't really do anything other that hide the issue in the first place. Third-party code could continue to call the constructor in this way. |
IMO, the bug is either that |
hm maybe it is better to just fix the function we know does it. |
Presumably, something like |
No as numpy gives empty arrays valid (uninitialized) memory for one block regardless. Though this should also trigger in that case harmless valgrind warnings. |
@@ -206,6 +206,9 @@ static NPY_GCC_OPT_3 void | |||
#else | |||
npy_uint64 temp0, temp1; | |||
#endif | |||
if (N == 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.
Could probably do with a comment along the lines of "dereferencing src
when N == 0
is not allowed
When creating the tuple view of np.where, make sure the arrays point to
valid memory when they are empty.
Numpy assumes that even empty arrays have valid memory, e.g. in the
source stride == 0 assignments.
Closes gh-8922.