The Bug Was in the Promise, Not the Pointer

Five lines. A bounds check, then a read. It compiles, it passes review, and it can read memory the program does not own. The caller never writes the word unsafe anywhere.
That is not a hypothetical. Microsoft's FORGE Lab recently published a set of memory-safety bugs it found in Rust's standard library — std and core, the two crates nearly every Rust program sits on — including cases where code written entirely in safe Rust can trigger undefined behavior. Some of the bugs were uncovered with Hyenas, the lab's AI-assisted vulnerability scanner.
The interesting part is not that Rust has bugs. It is where they live: not in the pointers, but in the promises.
What soundness means, in one sentence
Rust's type system rules out whole categories of memory bugs at compile time. But the standard library is built from small unsafe blocks — code where the compiler stops checking and the programmer takes responsibility — wrapped in safe functions. The wrapper's job is to be sound: no matter how safe code calls it, in any order, with any arguments, undefined behavior must be impossible.
Soundness is a promise about everyone else's code, not about yours. That is what makes it hard. You are not defending against the inputs you imagined; you are defending against every caller you will never meet.
And you have written this same wrapper. Not in Rust, necessarily — the pattern shows up anywhere an unchecked step hides behind a friendly interface: the internal library that validates a payload before handing it to a parser, the cache client that checks expiry and then trusts the entry, the platform module that confirms a resource exists and then acts on the name it was given. Same shape, same failure mode.
Two calls, one check
The clearest example from the research is the one you can spot in your own code. It goes roughly like this: take a generic value that can be viewed as a byte slice, ask it for that slice, compare the index against the slice's length, then read at that index with the bounds check switched off. The comment says SAFETY: we just checked that the index is in bounds, and it is telling the truth — about the slice it looked at.
But the type is chosen by the caller, and the conversion is a trait method the caller implements. A perfectly safe implementation is allowed to return a long slice the first time and an empty one the second. Two calls, two observations, one check. The read is now out of bounds, inside a function nobody would flag in review.
That is the whole bug class in miniature: the check and the use were not the same observation. If it sounds familiar, it is because it is the same failure as a time-of-check-to-time-of-use race, minus the threads. You verified a fact, time passed, and you acted on the fact.
The three things unsafe code gets wrong
The FORGE write-up groups the bugs into three patterns of misplaced trust. They are worth memorizing, because they transfer straight out of Rust.
1. Trusting code not to panic
Lots of low-level code works by breaking an invariant briefly, doing something fast, then restoring the invariant before returning. That is fine — as long as the function reaches the end. In Rust, a panic is an early exit: it aborts the current operation and unwinds, running destructors as it goes. If it fires in the middle of that window, the invariant stays broken, and the destructor that runs was written by someone who assumed it was intact.
A concrete case from the research: the standard library's map_windows iterator keeps its current window in a fixed-size buffer with exactly N initialized slots. Cloning that buffer copies elements one at a time. If an element's clone panics halfway through, the buffer is left in a state its own destructor does not expect, and the cleanup path touches memory that was never written.
Translate it: your invariant window contains a call to code you do not own — an allocation, a user callback, a destructor, a log handler — and that code is allowed to throw, panic, or be cancelled.
2. Trusting the caller's implementation
In Rust, a trait is an interface: a set of methods a type promises to provide. The caller supplies the implementation. So any function taking a generic parameter is running code written by someone whose motives you cannot audit, and they only had to satisfy the compiler — not your assumptions. Called twice, an implementation can return two different answers, and both are legal.
Every ecosystem has this. A plugin that returns a path. A hook that returns a config object. A tool call from an AI agent that returns a JSON blob matching a schema. The schema is not the behavior. The type is not the semantics.
3. Trusting the system underneath
The third pattern is quieter: the allocator, the OS, the platform, the hardware behaving as documented. This is where it stops being a Rust problem and becomes everyone's problem, because no amount of type checking reaches across that boundary. What you can do is write the assumption down, so that when the platform changes there is a sentence on file to search for.
A four-question audit
You do not need to know anything about Rust to run this on your own code. Pick one abstraction that hides an unchecked step — a parser, a cache, a permissions check, an agent tool — and ask:
- What do I assume is still true between the check and the use? Name it in one sentence. If you cannot, you have found the bug.
- What can leave this window early? Exceptions, panics, timeouts, cancellation, await points, a signal handler, a callback into code you do not own. Each one is an invisible exit taken while the invariant is half-broken.
- Do I call anything from outside my code more than once? If two calls can return two answers, which one did I check? Bind the result to a local variable and use that same local for both the check and the action. Or re-verify after the call. Never check one observation and act on another.
- If this goes wrong, is it loud or silent? A panic in a test is loud and cheap. A silently wrong byte read is expensive and permanent. Spend your caution on the silent ones.
The rule I keep coming back to: the check and the use must come from the same observation. Everything else is elaboration.
The fix is usually one line and usually free
In the slice example, the fix costs nothing at runtime: convert once, store the slice in a local, check that local, read from that local. Same number of instructions, one assumption fewer. If you cannot do that, that is your signal the abstraction is hiding something you do not control.
For the panic case, the standard tool is a drop guard: an object whose destructor restores the invariant during unwinding. It costs a few instructions on the happy path. The alternative — restructure so no invariant is ever broken — is cheaper still, and often means a defensive copy. A copy is one allocation; a soundness bug is a security advisory with your package name on it. Take the allocation when the window is rare, take the redesign when it is hot.
One real trade-off worth knowing: Rust can compile with panic = abort, where a panic kills the process instead of unwinding. That closes the window by removing the exit — and swaps a correctness risk for an availability risk. The standard library cannot make that trade for you; your crate might be able to, if everything above it accepts it. Decide on purpose.
Why this matters beyond the Rust community
Rust is no longer a lab language. Microsoft made it a Tier-1 internal language alongside C++, C#, and TypeScript, GitHub rewrote the Copilot agent runtime in it, and it is in Bun, Android, the Linux kernel, and Cloudflare's stack. Estimates put the number of people whose daily software touches Rust in the billions, almost none of whom know it.
So the FORGE findings are not really a story about one language's fragility. They are a reminder that safety guarantees relocate risk, they do not delete it. The compiler pushed memory bugs out of the average function and into a small number of carefully audited blocks — and the bugs followed. That is still a massive net win. It just means the remaining risk concentrates wherever a human decided to stop checking, which is exactly where review attention should concentrate too.
If you are hiring, the useful question is not whether someone knows Rust. It is: walk me through a promise your code makes to callers, and tell me what happens if it is broken halfway. The answer shows whether the person thinks in contracts. That skill is language-independent, and it survives the next framework.
Key Takeaways
- Soundness is a promise to unknown callers. A safe wrapper must hold under every legal use, not just the uses you pictured.
- Check and use must be one observation. Two calls, one check, is the bug — in Rust, in caches, in auth, in agent tool calls.
- Any early exit breaks an open invariant. Exceptions, panics, timeouts, cancellation and await points are invisible exits; guard the window or do not open it.
- The three misplaced trusts: code will not panic, the caller's implementation is honest, the platform behaves as documented. Assume all three can fail.
- Most fixes are free: bind once, add a drop guard, re-verify after the call. Pay for the copy when the window is rare; redesign when it is hot.
- Safety guarantees move risk, they do not remove it. Audit where the checking stopped, and hire people who can describe their contracts.