mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-24 21:16:10 +00:00
Rust Remove SafeSliceAccess for Arrays, and fix miri. (#6592)
* Fix Miri flag passing and bump Rust version. * Fix Miri problems from Arrays PR. SafeSliceAccess was removed for Arrays. It's kind of unsound. It has two properties: 1. EndianSafe 2. Alignment 1 We only need 1. in create_vector_direct to memcpy data. We both 1. and 2. for accessing things with slices as buffers are built on &[u8] which is unaligned. Conditional compilation implements SafeSliceAccess for >1byte scalars (like f32) on LittleEndian machines which is wrong since they don't satisfy 2. This UB is still accessible for Vectors (though not exercised our tests) as it implements SafeSliceAccess. I'll fix this later by splitting SafeSliceAccess into its 2 properties. Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
@@ -225,8 +225,8 @@ fn verify_struct_array_alignment() {
|
||||
let array_table = root_as_array_table(buf).unwrap();
|
||||
let array_struct = array_table.a().unwrap();
|
||||
let struct_start_ptr = array_struct.0.as_ptr() as usize;
|
||||
let b_start_ptr = array_struct.b().safe_slice().as_ptr() as usize;
|
||||
let d_start_ptr = array_struct.d().safe_slice().as_ptr() as usize;
|
||||
let b_start_ptr = array_struct.b().as_ptr() as usize;
|
||||
let d_start_ptr = array_struct.d().as_ptr() as usize;
|
||||
// The T type of b
|
||||
let b_aln = ::std::mem::align_of::<i32>();
|
||||
assert_eq!((b_start_ptr - struct_start_ptr) % b_aln, 0);
|
||||
@@ -272,8 +272,6 @@ mod array_fuzz {
|
||||
let arr: flatbuffers::Array<$ty, ARRAY_SIZE> = flatbuffers::Array::follow(&test_buf, 0);
|
||||
let got: [$ty; ARRAY_SIZE] = arr.into();
|
||||
assert_eq!(got, xs.0);
|
||||
#[cfg(target_endian = "little")]
|
||||
assert_eq!(arr.safe_slice(), xs.0);
|
||||
}
|
||||
#[test]
|
||||
fn $test_name() {
|
||||
@@ -317,13 +315,10 @@ mod array_fuzz {
|
||||
let arr: flatbuffers::Array<NestedStruct, ARRAY_SIZE> = flatbuffers::Array::follow(&test_buf, 0);
|
||||
let got: [&NestedStruct; ARRAY_SIZE] = arr.into();
|
||||
assert_eq!(got, native_struct_array);
|
||||
let arr_slice = arr.safe_slice();
|
||||
for i in 0..ARRAY_SIZE {
|
||||
assert_eq!(arr_slice[i], *native_struct_array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(miri))] // slow.
|
||||
fn test_struct() {
|
||||
quickcheck::QuickCheck::new().max_tests(MAX_TESTS).quickcheck(prop_struct as fn(FakeArray<NestedStructWrapper, ARRAY_SIZE>));
|
||||
}
|
||||
|
||||
@@ -1115,6 +1115,7 @@ mod roundtrip_byteswap {
|
||||
// fn fuzz_f64() { quickcheck::QuickCheck::new().max_tests(N).quickcheck(prop_f64 as fn(f64)); }
|
||||
}
|
||||
|
||||
#[cfg(not(miri))]
|
||||
quickcheck! {
|
||||
fn struct_of_structs(
|
||||
a_id: u32,
|
||||
|
||||
Reference in New Issue
Block a user