Skip to content

Commit 69307b5

Browse files
wasmparser: fix ahash::RandomState usage in no_std mode (#1536)
* wasmparser::fix ahash::RandomState usage in no_std The ahash::RandomState usage so far was incorrect in that it always used a new random initialization for each hash causing the same HashMap to create different hashes for the same hash inputs. * Remove compile-time-rng feature and add Default impl --------- Co-authored-by: Alex Crichton <alex@alexcrichton.com>
1 parent 1594eba commit 69307b5

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

crates/wasmparser/src/map.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,27 @@ use std::collections::hash_map::RandomState as RandomStateImpl;
111111

112112
// When the `std` feature is NOT active then rely on `ahash::RandomState`. That
113113
// relies on ASLR by default for randomness.
114-
#[derive(Default, Clone, Debug)]
114+
#[derive(Clone, Debug)]
115+
#[cfg(not(feature = "std"))]
116+
struct RandomStateImpl {
117+
state: ahash::RandomState,
118+
}
119+
115120
#[cfg(not(feature = "std"))]
116-
struct RandomStateImpl;
121+
impl Default for RandomStateImpl {
122+
fn default() -> RandomStateImpl {
123+
RandomStateImpl {
124+
state: ahash::RandomState::new(),
125+
}
126+
}
127+
}
117128

118129
#[cfg(not(feature = "std"))]
119130
impl BuildHasher for RandomStateImpl {
120131
type Hasher = ahash::AHasher;
121132

122133
#[inline]
123134
fn build_hasher(&self) -> ahash::AHasher {
124-
ahash::RandomState::new().build_hasher()
135+
self.state.build_hasher()
125136
}
126137
}

0 commit comments

Comments
 (0)