Skip to content

Commit 425deee

Browse files
authored
fix: align bytes ptr address for cacheable::from_byte (#8450)
* fix: cacheable::from_byte align bytes ptr address * ci: miri test add env MIRIFLAGS
1 parent d84e931 commit 425deee

File tree

6 files changed

+14
-1
lines changed

6 files changed

+14
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ jobs:
346346
echo 'debug = false' >> Cargo.toml
347347
348348
- name: Run test
349+
env:
350+
MIRIFLAGS: -Zmiri-tree-borrows -Zmiri-disable-isolation
349351
# reason for excluding https://github.com/napi-rs/napi-rs/issues/2200
350352
run: cargo miri test --workspace --exclude rspack_binding_options --exclude rspack_node -- --nocapture
351353

crates/rspack_cacheable/src/deserialize.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rkyv::{
66
bytecheck::CheckBytes,
77
de::Pool,
88
rancor::{BoxedError, Source, Strategy, Trace},
9+
util::AlignedVec,
910
Archive, Deserialize,
1011
};
1112

@@ -79,8 +80,13 @@ where
7980
let guard = ContextGuard::new(context);
8081
let mut deserializer = Pool::default();
8182
guard.add_to_pooling(&mut deserializer)?;
83+
// The `bytes` ptr address in miri will throw UnalignedPointer error in rkyv.
84+
// AlignedVec will force aligned the ptr address.
85+
// Refer code: https://github.com/rkyv/rkyv/blob/dabbc1fcf5052f141403b84493bddb74c44f9ba9/rkyv/src/validation/archive/validator.rs#L135
86+
let mut aligned_vec = AlignedVec::<16>::new();
87+
aligned_vec.extend_from_slice(bytes);
8288
deserialize_using(
83-
access::<T::Archived, DeserializeError>(bytes)?,
89+
access::<T::Archived, DeserializeError>(&aligned_vec)?,
8490
&mut deserializer,
8591
)
8692
}

crates/rspack_cacheable_test/tests/macro/cacheable_dyn.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rspack_cacheable::{cacheable, cacheable_dyn, from_bytes, to_bytes};
22

33
#[test]
4+
#[cfg_attr(miri, ignore)]
45
fn test_cacheable_dyn_macro() {
56
struct Context;
67

@@ -71,6 +72,7 @@ fn test_cacheable_dyn_macro() {
7172
}
7273

7374
#[test]
75+
#[cfg_attr(miri, ignore)]
7476
fn test_cacheable_dyn_macro_with_generics() {
7577
struct Context;
7678

crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rspack_cacheable::{cacheable, from_bytes, to_bytes};
22

33
#[test]
4+
#[cfg_attr(miri, ignore)]
45
fn test_manual_cacheable_dyn_macro() {
56
struct Context;
67

crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn_with_generics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rspack_cacheable::{cacheable, from_bytes, to_bytes};
22

33
#[test]
4+
#[cfg_attr(miri, ignore)]
45
fn test_manual_cacheable_dyn_macro_with_generics() {
56
struct Context;
67

crates/rspack_macros_test/tests/compiletest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#[test]
2+
#[cfg_attr(miri, ignore)]
23
fn ui() {
34
let t = trybuild::TestCases::new();
45
t.compile_fail("tests/ui/hook/*.rs");

0 commit comments

Comments
 (0)