-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Unsafe precondition violated in the x86_64 SIMD implementation of str.contains
#104726
Comments
…=thomcc" The current implementation seems to be unsound. See rust-lang#104726.
Tentatively opened a revert PR in #104727. |
Ugh. I ran it under miri with quite a combinatorial test that I thought should cover all the edge-cases. 😞 |
Last I checked (and a lot has happened since then so I could be working on outdated info -- @RalfJung might be able to confirm), miri can't catch |
the memory will be accessed after the get_unchecked so it should still be an invalid memory access when it's out of bounds. Unless I'm just doing some shortening slicing and then extending it again so that it's valid within the same allocation but not correct slicing. |
What @thomcc says is correct. The error here is in a situation like let arr = [0;32];
let slice = &arr[0..8];
slice.get_unchecked(16); Miri (without Stacked Borrows) will not complain about that since the index is in-bounds of the allocation. But the debug assertion will complain since you are causing library UB by going out-of-bounds of the slice. I don't quite understand your last comment, @the8472. |
It seems like the test is just insufficient. Even with debug asserts and overflow checks enabled it doesn't catch it. I'll have to reproduce it first to figure out what's missing. |
Ah, probably the probing for alternative tail bytes when the first and last byte in the needle are the same. |
Ooh, I was getting absolutely unexplainable compiler errors when building stage 1 libstd with a stage 0 rustc which was built with |
Possible, but it would also do incorrect things on x86-64 baseline |
#104735 has a proper fix |
PR #103779 added a x86_64 SIMD-based implementation of
str.contains(&needle)
to optimize searching into strings when the needle is at most 32 bytes long. Unfortunately, that implementation doesn't seem to be sound.When compiling the standard library with debug assertions on, running UI tests excluding
src/test/ui/process/no-stdio.rs
results in compiletest itself panicking before executing any test due to adebug_assert
in libcore:To reproduce the issue, use the following configuration file:
...and run:
cc @the8472 @thomcc
The text was updated successfully, but these errors were encountered: