RustSec logo

HistoryEditJSON (OSV)

RUSTSEC-2026-0097

Rand is unsound with a custom logger using rand::rng()

Reported
Issued
Package
rand (crates.io)
Type
INFO Unsound
References
Patched
  • >=0.10.1
  • <0.10.0, >=0.9.3
Unaffected
  • <0.7.0
Affected Functions
Version
rand::rng
  • >=0.9.0
rand::thread_rng
  • <0.10.0, >=0.7.0

Description

It has been reported (by @lopopolo) that the rand library is unsound (i.e. that safe code using the public API can cause Undefined Behaviour) when all the following conditions are met:

TryRng (previously RngCore) methods for ThreadRng use unsafe code to cast *mut BlockRng<ReseedingCore> to &mut BlockRng<ReseedingCore>. When all the above conditions are met this results in an aliased mutable reference, violating the Stacked Borrows rules. Miri is able to detect this violation in sample code. Since construction of aliased mutable references is Undefined Behaviour, the behaviour of optimized builds is hard to predict.

Affected versions of rand are >= 0.7, < 0.9.3 and 0.10.0.

Advisory available under CC0-1.0 license.