You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: A segfault in chararray (2.0.0dev0 regression) #25513
Astropy's tests against numpy's dev branch are currently choking on a segfault.
The issue can be boiled down to a pure numpy reproducer.
I wasn't able to setup my dev env properly to provide the full stack trace information yet (I'm working on it), but I could bisect the problem to 19396d2 (#25171)
Reproduce the code example:
importnumpyasnpcarr=np.chararray((2,), itemsize=25)
carr[:] = [b' 4.52173913043478315E+00', b' 4.95652173913043548E+00']
carr.replace(b"E", b"D")
Error message:
No response
Python and NumPy Versions:
2.0.0.dev0+git20231230.ee3124b
3.12.0 (main, Oct 27 2023, 11:50:57) [Clang 15.0.0 (clang-1500.0.40.1)]
When things don't give a segfault, on exit of ipython one gets "double free or corruption (out)" EDIT: or "malloc(): mismatching next->prev_size (unsorted)"
Also, is it intended that if the replacement string is too long to possibly be present, that an empty output is returned?
In [1]: a = np.array('abc').view(np.char.chararray)
In [2]: a.replace('012345', '')
Out[2]: array('', dtype='<U3')
In [3]: 'abc'.replace('012345', '')
Out[3]: 'abc'
Activity
mhvk commentedon Dec 31, 2023
Trying a bit, the segfault does not always happen immediately, but the results definitely are not always correct:
When things don't give a segfault, on exit of ipython one gets "double free or corruption (out)" EDIT: or "malloc(): mismatching next->prev_size (unsorted)"
mhvk commentedon Dec 31, 2023
Found the culprit if not yet the solution - the special-cased single-character case, and specifically the case where
memchris invoked; seenumpy/numpy/_core/src/umath/string_fastsearch.h
Lines 59 to 78 in bab7280
And indeed,
.find()is broken too:Basically,
s.bufgets overwritten to be the same asp.buf.mhvk commentedon Dec 31, 2023
Also, is it intended that if the replacement string is too long to possibly be present, that an empty output is returned?
mhvk commentedon Dec 31, 2023
I think I have a fix in #25515 (for all 3 issues that came up: the segfault, wrong
.findresult, and wrong.replace` result)