Skip to content
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

BUG: ensure static_string.buf is never NULL for a non-null string #25834

Merged
merged 2 commits into from
Feb 16, 2024

Conversation

ngoldbaum
Copy link
Member

@ngoldbaum ngoldbaum commented Feb 16, 2024

Right now if you do something like:

npy_static_string s = {0, NULL};
int is_null = NpyString_load(allocator, packed_string, &s)

Then it is possible to end up in a state where s.buf is NULL even though is_null is 0. It's much simpler to reason about things if that can only happen if packed_string is a null string.

This is causing intermittent CI failures due to UBSAN not liking this:

numpy/_core/tests/test_stringdtype.py::TestStringLikeCasts::test_void_casts[unset-True-strings1] ../numpy/_core/src/multiarray/stringdtype/casts.c:1464:9: runtime error: null pointer passed as argument 2, which is declared to never be null

See e.g. this run. It's not at all clear to me why that run hang for six hours instead of immediately crashing and also why the error from UBSAN never gets reported in the CI output. I was able to reproduce the failure locally though.

I'm hoping that explicitly specifying that we don't want to halt on UBSAN errors will avoid confusing CI hangs like the one above, but can't confirm.

@charris
Copy link
Member

charris commented Feb 16, 2024

C literal strings are NUL terminated, I assume that is taken into account.

@ngoldbaum
Copy link
Member Author

Yes, it just needs to be a valid non-null pointer. The size is always zero in this case. This is mainly to avoid passing NULL to e.g. memcpy, which is UB, or adding NULL checks before doing memcpy. It also makes things easier to reason about IMO.

@charris charris merged commit d5fb550 into numpy:main Feb 16, 2024
64 checks passed
@charris
Copy link
Member

charris commented Feb 16, 2024

Thanks Nathan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants