Memory Safety Bugs Found in Rust Standard Library
Microsoft's FORGE Lab found several memory safety issues in Rust's standard library, std and core. Some cases show that code written entirely in safe Rust can trigger undefined behavior[1]. The team used Hyenas, its research version of MDASH, an AI-powered vulnerability-scanning system, to help find some of the bugs.
The authors describe three recurring patterns of misplaced trust in unsafe code[2]: trusting code not to panic, trusting user-provided implementations to be correct, and trusting the underlying system. In the first pattern, a panic in the middle of an operation can leave data in a broken state. The example is MapWindows::clone (#156501), where a panic inside a user-provided clone can crash the program. The fix holds the half-built buffer in ManuallyDrop[4] until it is fully written, so a panic leaks it instead of dropping it.
The authors also note that the recently stabilized Allocator API makes panic safety bugs[3] harder to avoid, because much of the standard library assumes allocation never unwinds. They reported one case in BTreeMap::insert and others (#159334, #159368, #159370). They say that fixing such cases one by one would mean auditing the library's code broadly.
Read the original forge-blog.github.ioDiscussion
Sources
-
FORGE Lab
Memory Safety Bugs in Rust Standard Library


