diff --git a/crates/fast_rands/Cargo.toml b/crates/fast_rands/Cargo.toml index ea8eca8977..ad675b618f 100644 --- a/crates/fast_rands/Cargo.toml +++ b/crates/fast_rands/Cargo.toml @@ -50,7 +50,7 @@ serde = { workspace = true, default-features = false, features = [ ] } # serialization lib # Document all features of this crate (for `cargo doc`) document-features = { workspace = true, optional = true } -rand_core = { version = "0.9.5", optional = true } +rand_core = { version = "0.10.1", optional = true } pyo3 = { workspace = true, optional = true, features = ["serde", "macros"] } [lints] diff --git a/crates/fast_rands/src/lib.rs b/crates/fast_rands/src/lib.rs index 9c21b3a911..8c6db20f11 100644 --- a/crates/fast_rands/src/lib.rs +++ b/crates/fast_rands/src/lib.rs @@ -59,7 +59,7 @@ use core::{ }; #[cfg(feature = "rand_trait")] -use rand_core::{RngCore, SeedableRng}; +use rand_core::{Rng, SeedableRng, TryRng}; use serde::{Deserialize, Serialize}; #[cfg(feature = "alloc")] @@ -273,7 +273,7 @@ pub trait Rand { #[cfg(feature = "rand_trait")] impl Rand for T where - T: RngCore + SeedableRng + Serialize + for<'de> Deserialize<'de> + Debug, + T: Rng + SeedableRng + Serialize + for<'de> Deserialize<'de> + Debug, { fn set_seed(&mut self, seed: u64) { *self = Self::seed_from_u64(seed); @@ -333,17 +333,19 @@ impl_default_new!(Sfc64Rand); macro_rules! impl_rng_core { ($rand:ty) => { #[cfg(feature = "rand_trait")] - impl rand_core::RngCore for $rand { - fn next_u32(&mut self) -> u32 { - self.next() as u32 + impl TryRng for $rand { + type Error = core::convert::Infallible; + + fn try_next_u32(&mut self) -> Result { + Ok(self.next() as u32) } - fn next_u64(&mut self) -> u64 { - self.next() + fn try_next_u64(&mut self) -> Result { + Ok(self.next()) } - fn fill_bytes(&mut self, dest: &mut [u8]) { - rand_core::impls::fill_bytes_via_next(self, dest) + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> { + rand_core::utils::fill_bytes_via_next_word(dest, || self.try_next_u64()) } } }; @@ -872,24 +874,26 @@ mod tests { #[test] #[cfg(feature = "rand_trait")] fn test_rand_trait() { - use rand_core::{RngCore, SeedableRng}; + use rand_core::{Rng, SeedableRng, TryRng}; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] struct CountingRng(u64); - impl RngCore for CountingRng { - fn next_u32(&mut self) -> u32 { - self.next_u64() as u32 + impl TryRng for CountingRng { + type Error = core::convert::Infallible; + + fn try_next_u32(&mut self) -> Result { + Ok(self.try_next_u64()? as u32) } - fn next_u64(&mut self) -> u64 { + fn try_next_u64(&mut self) -> Result { self.0 += 1; - self.0 + Ok(self.0) } - fn fill_bytes(&mut self, dst: &mut [u8]) { - rand_core::impls::fill_bytes_via_next(self, dst); + fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> { + rand_core::utils::fill_bytes_via_next_word(dst, || self.try_next_u64()) } } @@ -901,7 +905,7 @@ mod tests { } } - // LibAFL's Rand trait is auto-implemented for all SeedableRng + RngCore types. + // LibAFL's Rand trait is auto-implemented for all SeedableRng + Rng types. assert!(CountingRng(0).coinflip(0.1)); } diff --git a/crates/libafl_bolts/Cargo.toml b/crates/libafl_bolts/Cargo.toml index 4a35614f7b..08e1088b74 100644 --- a/crates/libafl_bolts/Cargo.toml +++ b/crates/libafl_bolts/Cargo.toml @@ -147,7 +147,7 @@ rustversion = { workspace = true } [dev-dependencies] clap = { version = "4.5", features = ["derive", "env"] } -rand = "0.9.0" +rand = "0.10.1" chrono = "0.4.43" itertools = "0.14.0" diff --git a/crates/libafl_bolts/examples/simd/simd.rs b/crates/libafl_bolts/examples/simd/simd.rs index 7cef965b97..a0093dad3a 100644 --- a/crates/libafl_bolts/examples/simd/simd.rs +++ b/crates/libafl_bolts/examples/simd/simd.rs @@ -6,7 +6,7 @@ use libafl_bolts::simd::{ SimdMinReducer, SimdOrReducer, SimdReducer, VectorType, covmap_is_interesting_naive, covmap_is_interesting_simd, simplify_map_naive, simplify_map_simd, }; -use rand::{RngCore, rngs::ThreadRng}; +use rand::{Rng, rngs::ThreadRng}; fn default_map_size() -> usize { if std::env::var("CI").is_ok() { diff --git a/crates/libafl_cc/build.rs b/crates/libafl_cc/build.rs index abcbdaa0f1..9adb10f5d9 100644 --- a/crates/libafl_cc/build.rs +++ b/crates/libafl_cc/build.rs @@ -1,3 +1,5 @@ +#![allow(unused_imports)] + use core::str; #[cfg(any( target_vendor = "apple", diff --git a/crates/libafl_libfuzzer/runtime/Cargo.toml.template b/crates/libafl_libfuzzer/runtime/Cargo.toml.template index 70670242d0..d5f4cb4006 100644 --- a/crates/libafl_libfuzzer/runtime/Cargo.toml.template +++ b/crates/libafl_libfuzzer/runtime/Cargo.toml.template @@ -72,7 +72,7 @@ libc = "0.2.159" log = { version = "0.4.22", features = ["release_max_level_info"] } mimalloc = { version = "0.1.43", default-features = false } num-traits = { version = "0.2.19", default-features = true } -rand = "0.8.5" +rand = "0.10.1" serde = { version = "1.0.228", default-features = true, features = [ "derive", ] } # serialization lib diff --git a/fuzzers/baby/tutorial/Cargo.toml b/fuzzers/baby/tutorial/Cargo.toml index 104e1b034f..d73ea0431e 100644 --- a/fuzzers/baby/tutorial/Cargo.toml +++ b/fuzzers/baby/tutorial/Cargo.toml @@ -35,11 +35,12 @@ libafl_targets = { path = "../../../crates/libafl_targets", features = [ serde = { version = "1.0.228", default-features = false, features = [ "alloc", ] } # serialization lib -lain = { version = "0.5.6", features = [ +lain = { version = "0.5.7", features = [ "serde_support", -], git = "https://github.com/AFLplusplus/lain.git", rev = "6ac90a35cfff15e314cf33b098f6cac4691c7ab3" } # We're using a lain fork compatible with libafl's rand version +], git = "https://github.com/AFLplusplus/lain.git", rev = "8e2c083670f76acbd7105be2d7f5a58fc38291c0" } # We're using a lain fork compatible with libafl's rand version # TODO Include it only when building cc -libafl_cc = { path = "../../../crates/libafl_cc" } +libafl_cc = { path = "../../../crates/libafl_cc", default-features = false } +log = { version = "0.4.22", features = ["release_max_level_info"] } [lib] name = "tutorial"