TL;DR
Bun’s recent Rust rewrite has been found to fail basic Miri checks, revealing undefined behavior in code marked as safe Rust. This raises questions about the safety and correctness of Bun’s new codebase.
Recent reports indicate that Bun’s new Rust codebase fails fundamental Miri checks, allowing undefined behavior (UB) in code declared as safe Rust, raising safety and correctness concerns.
Developers analyzing Bun’s recent Rust rewrite discovered that the code fails to pass basic Miri checks, a tool used for detecting undefined behavior in Rust programs. Specifically, a snippet involving unsafe code constructs a dangling reference, which leads to UB. The failure was highlighted on Hacker News, where users pointed out that the code performs an invalid operation, despite being marked as safe Rust.
The problematic code involves constructing an invalid slice from a raw pointer, which results in undefined behavior according to Rust’s safety guarantees. The specific error occurs at src/main.rs:97, where unsafe code creates a slice from a raw pointer that no longer has valid provenance, leading to potential memory safety violations.
Why It Matters
This development matters because it questions the safety guarantees that Bun claims to uphold with its Rust rewrite. Allowing UB in safe Rust code can lead to crashes, security vulnerabilities, and unpredictable behavior, undermining trust in Bun’s platform. Given Rust’s emphasis on safety, such issues could impact Bun’s reputation and adoption among developers seeking reliable, secure runtime environments.
Rust Miri tool
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Background
Bun recently announced a rewrite of its core components in Rust, aiming to improve performance and safety. However, early testing with Miri, Rust’s tool for detecting undefined behavior, revealed that the new code fails basic safety checks. Miri is widely used in the Rust community to ensure code correctness, especially for unsafe code segments.
Prior to this, Bun’s development was focused on performance improvements, but the recent findings highlight potential safety flaws that could have serious implications if not addressed. The issue appears to be related to unsafe code blocks that handle raw pointers, which are notoriously difficult to get right in Rust.
“error: Undefined Behavior: constructing invalid value of type &[u8]: encountered a dangling reference… this indicates a bug in the program.”
— Hacker News user
“Unsafe code must be carefully audited; failing Miri checks suggests the code isn’t as safe as claimed.”
— Rust community member

CRC Evapo-Rust, Heavy-Duty Rust Remover, Reusable, Acid-Free, Non-Corrosive, Water-based, 32 oz, Removes Rust to Bare Metal
EVAPO-RUST RUST REMOVER: Evapo-Rust effortlessly removes rust from automotive parts, hardware, tools, cookware, and antiques without any scrubbing…
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What Remains Unclear
It is not yet clear whether this failure is isolated to specific parts of Bun’s code or indicative of broader safety issues within the entire codebase. The developers have not issued a formal statement or patch addressing the problem, and the extent of potential vulnerabilities remains unknown.

Rust for C Engineers: Safe Systems Programming
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What’s Next
Next steps include Bun developers conducting a thorough review of their Rust code, fixing the unsafe code segments, and rerunning Miri checks to ensure safety. Community members expect an official update or patch within the coming weeks, along with further testing to validate the safety of the codebase.

Write Powerful Rust Macros
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Key Questions
What is Miri and why is it important?
Miri is a Rust tool used to detect undefined behavior in programs, especially in unsafe code. Passing Miri checks is crucial for ensuring code safety and correctness.
What does undefined behavior mean in Rust?
Undefined behavior occurs when code performs invalid operations that the language does not define a behavior for, potentially leading to crashes, security issues, or data corruption.
Could this issue affect Bun’s overall stability?
Potentially yes, if unsafe code segments are not properly fixed, it could lead to runtime crashes or security vulnerabilities, undermining Bun’s reliability.
Is this a common problem in Rust projects?
While Rust emphasizes safety, unsafe code is sometimes necessary, but it must be carefully audited. Failures in static analysis tools like Miri are rare but serious when they occur.