Bun Rust rewrite: "codebase fails basic miri checks, allows for UB in safe rust"

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 Kutter - Stops Rust and Converts Rust Spots to Leave A Primed Surface Ready to Paint, Professional Rust Repair Manufactured in USA – Sprayer Included

Rust Kutter – Stops Rust and Converts Rust Spots to Leave A Primed Surface Ready to Paint, Professional Rust Repair Manufactured in USA – Sprayer Included

A rust converter is a specialized product designed to convert rust into a more stable and non-reactive compound…

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

Evapo-Rust ER012 Heavy Duty – 128 oz., Rust Remover for Auto Parts, Hardware, Antiques | Rust Removers and Chemicals

Evapo-Rust ER012 Heavy Duty – 128 oz., Rust Remover for Auto Parts, Hardware, Antiques | Rust Removers and Chemicals

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 Fundamentals for Complete Beginners: Complete Beginner's Guide to Memory Safety and Ownership Concepts (Rust Fundamentals Mastery Book 1)

Rust Fundamentals for Complete Beginners: Complete Beginner's Guide to Memory Safety and Ownership Concepts (Rust Fundamentals Mastery Book 1)

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

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.

You May Also Like

Security researcher says Microsoft built a Bitlocker backdoor, releases exploit

A security researcher alleges Microsoft secretly embedded a backdoor in BitLocker and has released an exploit, raising security concerns.

GitHub confirms breach of 3,800 repos via malicious VSCode extension

GitHub has confirmed that approximately 3,800 internal repositories were compromised after a malicious VS Code extension was installed by an employee.

Facebook is paying people overseas promoting Alberta separatism

Facebook is reportedly paying international users to promote Alberta separatist movements, raising concerns over foreign influence in regional independence efforts.

Kash Patel’s Apparel Site Is Trying To Trick Visitors Into Installing Malware

A website associated with Kash Patel has been accused of attempting to trick visitors into installing malware, raising security concerns.