Miri: an Undefined Behavior detection tool for Rust

AI-generated summary of reporting by GitHub Opensource Projects. Read the original for the full story.

Why it matters

Rust developers who write unsafe code can now catch memory bugs, data races and leaks in CI that the compiler and test suites would miss until production.

Read this as

Miri is a free checker for the Rust programming language, made by Rust's own organization. It runs your program on an interpreter and flags 'undefined behavior', mistakes like reading memory that has been freed, which the compiler's normal type checks cannot catch in code marked unsafe. It also emulates other computer architectures and reports memory leaks. Anyone maintaining Rust code with unsafe sections gains an extra safety net in their test suite.

Rust's core safety promise only holds if developers correctly uphold the contract in 'unsafe' blocks, and Miri is the maintained, official tool that verifies this. It has already caught numerous real-world bugs, with a public list maintained by the Rust organization. It is free via rustup but requires a nightly toolchain and is not a complete check, it explores only one possible execution per run. Teams shipping unsafe Rust should add it to testing; there is no cost or vendor lock-in.

Miri interprets cargo project binaries and tests on a platform-independent interpreter, detecting out-of-bounds accesses, use-after-free, uninitialized data, misaligned references, intrinsic precondition violations, invalid bools, data races, and leaks unreachable from globals. Experimental Stacked Borrows and Tree Borrows aliasing checks are included. Isolation replaces entropy, clocks and environment for deterministic runs (disable with -Zmiri-disable-isolation); -Zrandomize-layout exposes layout assumptions. It requires a nightly toolchain, uses its own UB approximation rather than a formal spec, tests one execution path per run, and its fake RNG is unsuitable for cryptography.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

Miri Rust cargo Stacked Borrows Tree Borrows rustup

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading