[KongchangAI]
· 2 min read· 1,076 words

Rust cURL Clone Uses 4,832 unsafe Blocks—Is the Memory Safety Myth Broken?

Rust cURL Clone Uses 4,832 unsafe Blocks—Is the Memory Safety Myth Broken?

Rust cURL clone with 4,832 unsafe blocks raises doubts about its memory safety claims and rewrite motives.

The article examines a cURL clone rewritten in Rust, noting 4,832 `unsafe` keywords that weaken the "Rust means memory safety" narrative. It explains that `unsafe` shifts safety responsibility from compiler to developer, and introduces Fil-C as a comparison: Fil-C recompiles existing C/C++ code for memory safety without source changes and has been used for GNOME and browsers. The author argues that choosing Rust over Fil-C suggests motivation closer to identity than memory safety, and reframes the debate around when rewriting C tools in Rust is justified.

A cURL clone rewritten in Rust recently sparked controversy: the code contains 4,832 occurrences of the unsafe keyword. For a language that flies the flag of "memory safety," that number alone is a signal worth digging into.

Why the Rust cURL Clone Matters

The core utilities got cloned in Rust.

cURL is practically part of the internet's infrastructure—whether you realize it or not, you use it every day. Rewriting a foundational tool like this in Rust isn't surprising in itself. From coreutils to sudo, rewriting system tools in Rust has become a trend.

The issue isn't "someone rewrote something in Rust again"—it's how much persuasive force the core value this rewrite claims, memory safety, still carries in the face of nearly five thousand unsafe calls.

What the unsafe Keyword Actually Means

Rust's unsafe keyword lets developers bypass the compiler's safety checks to perform operations the compiler can't verify (such as raw pointer manipulation or calling external C functions). It doesn't mean "the code is definitely broken," but every use shifts the safety responsibility from the compiler to the developer.

For a Rust project containing thousands of unsafe calls, it's hard to sum up its memory safety with a simple "it's written in Rust, so it's safe." The original critique is blunt: if even a foundational tool like cURL can't be implemented in Rust without heavy use of unsafe, then the value of the "memory safety" label deserves a question mark.

Rust's unsafe block is essentially a contract: the compiler no longer verifies whether operations inside the block satisfy memory safety rules—the developer guarantees it instead. Common triggers include dereferencing raw pointers, calling extern C functions, accessing mutable statics, implementing unsafe trait, and manipulating union fields. Notably, an unsafe block can be tiny or span hundreds of lines; the number of occurrences alone doesn't directly indicate risk, but a count in the thousands usually means the project relies heavily on FFI or manual memory management. Related features include unsafe fn (where the caller must uphold preconditions) and the #[deny(unsafe_code)] attribute, often used to prohibit unsafe at the library level and make safety boundaries explicit. The community also has tools like Miri, an interpreter that can detect undefined behavior in unsafe code, though it can't cover every path that interacts with external C code.

Fil-C Provides Another Frame of Reference

Case in point.

The original article offers a compelling comparison: Fil-C. It's a C/C++ compiler focused on "fanatical compatibility memory safety." It recompiles existing C/C++ code to gain memory safety protection.

Fil-C has its costs: it supports only a few platforms and incurs a small runtime overhead. But it can compile existing cURL source directly into a memory-safe version without modifying the code. Compared with the Rust cURL running with thousands of unsafe calls, which approach provides more thorough memory safety coverage isn't hard to judge.

The original article also notes that Fil-C has been used to compile complex software such as the GNOME desktop environment and browsers, producing the first truly "memory-safe" browsers.

You would have done it in Fil-C.

Fil-C's memory safety model is based on pointer capabilities: every pointer carries metadata such as bounds and type, and any out-of-bounds access, use-after-free, or type confusion is intercepted by runtime checks. It doesn't require source code to conform to a subset; instead, it uses compiler instrumentation and a custom runtime (paired with a modified libc). This means existing C/C++ projects usually only need to be recompiled rather than rewritten line by line. The costs fall mainly in two areas: runtime overhead (allocator metadata, pointer checks) and platform/toolchain compatibility—current support is limited, and there may be friction with code that relies on inline assembly or special memory layouts. Fil-C isn't positioned to replace Rust; rather, it offers a low-migration-cost memory safety path for existing C/C++ code, which is the fundamental reason the original article uses it as a point of comparison.

What's the Real Motivation?

The original author's judgment is quite sharp: if memory safety were truly the primary goal, choosing Fil-C to compile existing C code would be more efficient and safer than rewriting in Rust. Choosing Rust over Fil-C shows that the motivation driving these rewrite projects isn't memory safety, but something closer to identity—"I rewrote it in Rust" is itself the goal.

This view carries an obvious personal stance and emotional expression, but the engineering logic it points to deserves serious consideration: if a rewrite project brings no new functionality, has bloated code, and has memory safety metrics worse than simply recompiling the original code, then its technical justification needs a clearer argument.

It's absolutely, absolutely fascinating.

What This Really Reveals

There's no dispute that Rust's borrow checker and ownership model provide strong safety guarantees in code that doesn't use unsafe. But when a project needs to interact frequently with the C ecosystem and make low-level system calls, using unsafe is almost inevitable.

The focus of the debate shouldn't be "is Rust good or bad," but a more specific question: under what conditions is rewriting an existing C tool in Rust a reasonable engineering decision? If the answer is "in most cases you can't avoid heavy unsafe," then the "rewrite means safe" narrative needs a more honest examination.

The original article's tone is full of sarcasm, and some analogies go beyond the scope of technical discussion. But the core question it raises—how much safer is a Rust rewrite bought with nearly five thousand unsafe blocks than simply recompiling the original code under Fil-C?—is a technical question the Rust community should answer head-on, not dismiss with "you don't understand Rust."

One-line Summary

A Rust cURL clone contains 4,832 unsafe blocks, raising questions about its memory safety claims and rewrite motivations.

Paragraph Summary

The article examines a cURL clone rewritten in Rust, pointing out that 4,832 unsafe keywords appear in its code, undermining the "Rust means memory safety" narrative. The author explains what unsafe means—it shifts safety responsibility from the compiler to the developer—and introduces Fil-C as a comparison: Fil-C can directly recompile existing C/C++ code for memory safety without rewriting source, and has been used for complex projects like GNOME and browsers. The author concludes that choosing a Rust rewrite over Fil-C recompilation suggests the motivation is closer to identity than memory safety. The article ultimately shifts the debate from "is Rust good" to a more specific engineering question: under what conditions is rewriting C tools in Rust justified.

#Rust#cURL#unsafe#memory safety#Fil-C#C/C++#rewrite
Share:

Related articles