Rust Remove SafeSliceAccess for Arrays, and fix miri. #6592
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resubmitting #6583 and fixing associated problems.
Looks like the Miri test in
RustTest.sh
didn't catch errors in #6548 related to the unsoundness ofSafeSliceAccess
.I removed
SafeSliceAccess
for Arrays, and probably should do so for Vectors in the future too.Calling
safe_slice() -> &[T]
requiresT
to bealign_of::<T>() == 1
.I actually almost saw this error in #6548 but figured it was fine because I thought SafeSliceAccess was only implemented in endian-safe, alignment-1, types; u8, i8, bool, and flatbuffers structs; however we do conditional compilation that adds SafeSliceAccess to larger scalars on little-endian targets... 🤦 This is just wrong and callers of
safe_slice()
may get alignment errors.I left in the conditional compilation since
create_vector_direct
depends onSafeSliceAccess
but only requires property 1 (its doing memcpy, no dereferencing). We test and advertise that function for vectors of larger scalars so people may be using it.create_vector_direct
is fine but if clients useflatbuffers::Vector<f32>::safe_slice()
, that triggers UB.In a future PR, I will split SafeSliceAccess into the two properties to deprecate the conditional compilation and make things safe.
@3ddi @krojew