rust-sanitizers-mirilisted
Install: claude install-skill po4yka/rust-skills
# Rust Sanitizers and Miri
Runtime and interpreter-based safety validation for Rust: ASan, TSan and MSan
through `RUSTFLAGS`; UBSan through the C compiler on a C or C++ dependency;
Miri for undefined behaviour (UB) in unsafe code; HWASan and MTE for on-device
Android validation; ASan and TSan for iOS; and the rules to read the reports
that these tools produce.
## 1. Select the tool
Select the tool from the bug class, not from habit. Each tool finds a different
class and misses the others.
| Bug class | Tool to use | Do not use |
|---|---|---|
| Aliasing rule breach, invalid value, provenance error | Miri | ASan (does not model Rust rules) |
| Heap overflow, use-after-free, double free at runtime | ASan, HWASan or MTE | Miri, if the path reaches FFI |
| Data race between threads | TSan, or Miri with `-Zmiri-seed` | ASan |
| Read of uninitialized memory | MSan or Miri | ASan |
| Integer overflow or null deref in a C or C++ dependency | UBSan, built with clang `-fsanitize=undefined` | Miri (does not execute C or C++), `RUSTFLAGS` (rustc has no UBSan option) |
| UB inside a C or C++ dependency | ASan, HWASan or MTE | Miri (cannot interpret C or C++) |
| Type or lifetime error | `cargo check --locked`, Clippy | any sanitizer |
Full overhead and requirement comparison: `references/miri-ub-patterns.md`.
Two rules follow from the table:
- Miri sees Rust semantics but cannot execute foreign code.
- Sanitizers execute foreign code but do not know the Rust aliasing model.
Run bo