Closed wfraser closed 1 year ago
Probably the simplest fix is to just:
diff --git a/rust/vendor/caches-0.2.3/src/lfu/tinylfu/bloom.rs b/rust/vendor/caches-0.2.3/src/lfu/tinylfu/bloom.rs
index c9485f6d2f3a1..ca73e069ed8e4 100644
--- a/rust/vendor/caches-0.2.3/src/lfu/tinylfu/bloom.rs
+++ b/rust/vendor/caches-0.2.3/src/lfu/tinylfu/bloom.rs
@@ -96,7 +96,9 @@ impl Bloom {
let offset = ((idx % 64) >> 3) as u64;
let ptr = (raw + offset) as *mut u64;
unsafe {
- *ptr |= MASK[idx % 8] as u64;
+ ptr.write_unaligned(ptr.read_unaligned() | MASK[idx % 8] as u64);
}
}
@@ -106,7 +108,7 @@ impl Bloom {
let offset = ((idx % 64) >> 3) as u64;
let ptr = (raw + offset) as *mut u64;
unsafe {
- let r = (*ptr >> (idx % 8)) & 1;
+ let r = (ptr.read_unaligned() >> (idx % 8)) & 1;
r == 1
}
}
also note, the tests in bloom.rs
are currently broken, but I commented out the last 3 and it passes with this change.
Thanks for reporting! Fixed in 0.2.5
.
Thanks! Amazing quick fix!
Just one small question: the 0.2.5 release seems to have also added a dependency on getrandom
(which also pulls in more deps), but I don't see this being used anywhere in the code. Is this something that can be removed?
Thanks! Amazing quick fix!
Just one small question: the 0.2.5 release seems to have also added a dependency on
getrandom
(which also pulls in more deps), but I don't see this being used anywhere in the code. Is this something that can be removed?
Ah, It is a feature gate for supporting the target wasm32 family (rand requires). It should only be compiled for wasm family targets.
Rust now checks for misaligned pointer access in debug builds, which it seems
WTinyLFUCache
is always doing.(edit: note my host is aarch64, but this issue was also observed on an x86_64 Linux machine)