AI Trends

Anthropic Study Says Claude Exposed a Compiler Type-Safety Issue with Five Lines of Safe Rust Code

36Kr · AIUpdated Dec 4 20:46

AI summary

Anthropic’s Frontier Red Team published a study titled “Finding Logic Bugs Without General-Purpose Bug Oracles,” saying that Claude discovered dozens of type-safety issues in the Rust compiler, including a five-line Safe Rust counterexample that can access freed memory. The study had the model construct informal correctness proofs in natural language and create a PoC where a claim could not be derived. Some issues have been fixed, while the five-line case is still being addressed. Anthropic stressed that these are compiler bugs, not security vulnerabilities in the traditional sense, and members of the Rust community also noted that compiler defects do not mean Rust as a whole has lost its safety guarantees.

Why read this

SelectedAI score 80

The study demonstrates a method for locating logic flaws through informal correctness proofs, using a Rust compiler case to show how large language models can construct a PoC from a point where a proof breaks down.

Topics

Tags

Body · AI translation

This one is enough to make everyone who has been clamoring to “rewrite everything in Rust” completely lose it!

In Anthropic’s Frontier Red Team’s latest study, Finding Logic Bugs Without General-Purpose Bug Oracles, Claude managed to break the compiler of Rust—a language renowned for its memory safety and high performance.

Without writing a single line of unsafe code, Claude uncovered dozens of type safety issues in the Rust compiler in one go.

One counterexample consisting of just five lines of ordinary code could even make a program directly access invalid memory, triggering a classic memory error.

Although several of these bugs have now been fixed, the five-line counterexample was designated high priority as early as August and remains stuck in the remediation process, with the fix still incomplete.

As soon as the news broke, overseas netizens immediately jumped to conclusions and rushed to spread the word, exclaiming:

To understand why this was enough to make programmers collectively lose their composure, we first need to look at the core ironclad rule Rust originally established:

As long as you do not manually use the unsafe keyword, any valid code that passes the Rust compiler’s checks must never be able to access invalid memory.

It is worth noting that Rust was created precisely to eliminate memory errors.

In 2006, Mozilla programmer Graydon Hoare resolved to create the language after his apartment building’s elevator repeatedly broke down because of C/C++ memory errors, forcing him to angrily climb 21 flights of stairs time and again.

Armed with the trump card of “memory safety,” Rust won over Microsoft—which once disclosed that 70% of its CVE vulnerabilities stemmed from C/C++ memory issues—to rewrite 36,000 lines of the Windows kernel in Rust, while Linux 6.1 and Google’s Android also placed successive bets on the language.

A classic meme even circulated in programming circles: writing C++ is like juggling flaming chainsaws, while writing Rust is like doing parkour in a full set of protective gear—you cannot hurt yourself no matter what stunts you pull.

This time, however, Claude punched straight through the Rust compiler’s safety defenses.

Anthropic’s research team gave Claude a task: use “informal correctness proofs” to prove that Safe Rust really is type-safe, just as it promises.

An informal correctness proof is a method inspired by formal verification: a large model is asked to write a natural-language document structured like a mathematical proof—including theorems, definitions, assumptions, and lemmas—to derive and prove properties of the target program.

The proof does not need to be rigorously flawless. In essence, it is a tool that helps AI follow the logic and look for faults. Whenever a claim in the proof cannot be derived from the existing code, Claude follows the trail and directly constructs a concrete input, or PoC, that breaks it.

Claude’s reasoning process ended up uncovering dozens of type safety bugs.

So how exactly did Claude trigger this bug?

First, the code defines a two-dimensional array, arr, whose sole element is an exclusive smart pointer to an i32 integer on the heap—meaning that the integer has only one owner.

On the next line, the code attempts to bind alias to an exclusive mutable reference to that sole element, namely arr[0][0].

The clever trick occurs while the second index value, [0], is being calculated:

Inside this index expression, the code transfers, or moves, ownership of arr’s inner array to the variable row, then immediately calls drop(row), freeing the exclusive pointer on the spot and reclaiming the i32 memory on the heap along with it!

In principle, once ownership had been moved away, the compiler should immediately have determined that arr no longer held a valid value and rejected the code with an error.

But the Rust compiler went “blind” at exactly this point.

It failed to connect “the transfer of arr’s ownership inside the index expression” with the ongoing external “borrow of arr[0][...],” and astonishingly gave the code a green light all the way through!

As a result, by the time the reference to arr’s sole element was finally assigned to alias, the underlying memory had already been freed.

In this way, a piece of 100% valid Safe Rust code openly accessed invalid memory and could even be used to introduce a type-confusion vulnerability into Rust code that appeared absolutely safe.

Netizens erupt: Is Rust finished, or is this free debugging?

The fact that Rust’s own core defenses could be bypassed with just a few lines of code instantly set social media ablaze.

Blogger @Binkg was the first to drive the conversation, exclaiming that the compiler had accepted this code since 2019 and that running it directly printed garbage memory data:

In the comments, netizens eager to watch the spectacle piled on with their own jokes.

Just as we showed at the beginning:

Everyone who has recently refactored their code into Rust is probably breaking out in a cold sweat right now.

But as increasingly outlandish claims that “Rust is doomed” spread, prominent figures quickly stepped in to put out the fire.

One netizen pointed out that this was not bad news at all, but rather an excellent round of free debugging:

This is obviously good news: once these bugs are fixed, Rust will only become stronger.

That argument is so stupid. How could this possibly spell the end of Rust? Rust’s selling point has always been “safer defaults,” and it still delivers exactly that. No language is perfect; Rust has simply tried from the outset to help everyone eliminate the vast majority of potential hazards.

Even Rust community veteran Steve Klabnik, author of The Rust Programming Language, personally joined the discussion by reposting the news and dispelling the rumor:

Rust is not finished. Bugs in compilers are perfectly normal.

To prove that everyone was overreacting, Steve Klabnik directly posted the list of issues carrying the I-unsound label—meaning unsound or in violation of safety guarantees—in Rust’s official GitHub repository.

A look at the list shows that there are currently a full 178 similar compiler bugs with Open status!

When a netizen asked, “If compiler bugs make programs unsafe, how is Rust any different from languages that are inherently unsafe?” Steve offered a very fair response:

Bugs can be fixed, but a design that is fundamentally unsafe cannot. If a language is considered unsafe whenever even one compiler bug remains unfixed, then no programming language in the world is safe, and the concept itself becomes meaningless.

In fact, Anthropic’s own red team specifically emphasized in its report that the issues it found in the Rust compiler were merely bugs, not security vulnerabilities in the traditional sense.

The real reason the team chose the Rust compiler as its target was to flex its muscles and demonstrate how far large models have evolved in discovering “logic bugs.”

It is all about pumping the stock price—damn it, it is still all about pumping the stock price!

What exactly is Anthropic’s red team doing?

Besides uncovering bugs in the Rust compiler, Claude also tore through bugs in three other targets in this study—

Caliptra, an entirely Rust-based chip security foundation; an Apple macOS privilege-escalation 0-day; and more than a hundred vulnerabilities in the Linux kernel’s eBPF verifier.

At the same time, blind testing Claude against 21 historical logic bugs also confirmed the principle that “simpler is stronger.”

Giving the AI specialized tools such as fuzzing and symbolic execution produced scores of zero across the board. Simply letting Claude Code read the code, by contrast, crushed the entire field: Mythos 5.2 found 15, while all the experiments together also uncovered 316 additional vulnerabilities.

Previously, the Frontier Red Team—the Anthropic team dedicated to probing the limits of models’ high-risk capabilities—also launched Project Glasswing, using Claude Mythos to uncover thousands of conventional 0-days in mainstream software.

Reference links

This article originally appeared on the WeChat public account “QbitAI” (ID: QbitAI), written by henry, and is republished by 36Kr with authorization.

Source

36Kr · AI