Microsoft FORGE Lab uses AI to find three kinds of misplaced trust in Rust standard library unsafe code
Rust's type system and ownership model rule out many memory-safety problems, but safe APIs such as Vec and String in the standard library still wrap unsafe code. Inside an unsafe block the programmer must guarantee conditions the compiler cannot check, and that duty carries to the outer safe API: no matter how safe code calls it, undefined behaviour must not occur. Microsoft FORGE Lab used the AI-assisted scanning tool Hyenas, a research version of MDASH, to find several kinds of soundness bug in std and core, where safe code can trigger undefined behaviour through a safe API, and grouped them into three kinds of misplaced trust.
Rust's type system and ownership model rule out many memory-safety problems, but safe APIs such as Vec and String in the standard library still wrap unsafe code. Inside an unsafe block the programmer must guarantee conditions the compiler cannot check, and that duty carries to the outer safe API: no matter how safe code calls it, undefined behaviour must not occur. Microsoft FORGE Lab used the AI-assisted scanning tool Hyenas, a research version of MDASH, to find several kinds of soundness bug in std and core, where safe code can trigger undefined behaviour through a safe API, and grouped them into three kinds of misplaced trust.
The author's core judgement is that the hard part of unsafe code is not syntax but working out what can be trusted. The first kind is trusting that code will not panic. For example, MapWindows::clone first builds an uninitialised buffer and then calls the user's T::clone to fill it; if clone happens to panic, stack unwinding destroys memory that was never written. The fix is to wrap it in ManuallyDrop until writing is complete, so unwinding leaks the memory instead of destroying it. The Allocator API fell into the same trap: the standard library aborts the process when allocation fails by default, but a custom allocator may unwind, so Rust 1.100 simply rules that allocator implementations must not unwind. The second kind is trusting that an implementation supplied by the caller is correct. The fast path of str::replace assumes a single-byte pattern must be ASCII, but a custom Pattern can report 0x80, producing a String with invalid UTF-8; the fix changes StringPattern from &[u8] to &str so the type itself guarantees it. join was fixed once in 2020 and overflowed again in 2026 through another path, showing that such fixes easily cover only half the problem. The third kind is trusting that underlying system state does not change, which the author sees as the most valuable new area for AI scanning: process::exit tears down the main thread's alternate signal stack, and exec rewrites the global environ while holding only a read lock. Both bugs affect stable releases, and the first lay dormant for nearly 11 years. The author also notes that most of these bugs need deliberately constructed trigger conditions, which does not mean programs using the standard library have vulnerabilities.
The author argues that Rust's strict standard is worth keeping: fixing soundness problems once in the library is cheaper than having every user defend against them separately. For people writing unsafe code, the transferable lesson is to treat every external call as a possible early exit or wrong answer, and to prefer pinning assumptions down in types.