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

TL;DR

Bun’s new Rust codebase does not pass Miri static analysis, exposing undefined behavior in code marked as safe Rust. This raises concerns about stability and security. The issue is confirmed through recent error reports, but full scope remains under investigation.

Recent reports indicate that Bun’s new Rust codebase fails basic Miri checks, revealing undefined behavior in code marked as safe Rust, raising concerns about the stability and security of the project.

Developers working on Bun, a popular JavaScript runtime, recently attempted a rewrite of its core components in Rust. However, during static analysis with Miri, a Rust interpreter used to detect undefined behavior, several checks failed. Specifically, an error was identified involving the construction of invalid values of type &[u8], which led to undefined behavior (UB). The error message highlighted an unsafe operation that could cause memory safety violations, even in code declared as safe Rust.

The failure was confirmed through logs showing Miri errors, including a dangling reference and invalid raw pointer usage. The problematic code involved unsafe blocks, particularly lines where raw pointers are dereferenced and slices are created without proper provenance checks. This indicates that the code, despite being marked as safe, permits UB, which can lead to crashes, data corruption, or security vulnerabilities.

Why It Matters

This development matters because it exposes potential security and stability flaws in Bun’s core, especially as the project transitions from JavaScript to a Rust-based implementation. Undefined behavior in safe Rust is particularly concerning, as it undermines Rust’s guarantees of memory safety. If these issues are not addressed, they could lead to runtime crashes or exploitation, impacting users relying on Bun for production workloads.

Mastering Biome.js: A Complete Guide to Rust-Powered Linting and Formatting for JavaScript and TypeScript

Mastering Biome.js: A Complete Guide to Rust-Powered Linting and Formatting for JavaScript and TypeScript

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Background

Bun announced a major rewrite of its core in Rust earlier this year, aiming to improve performance and safety. Rust’s safety guarantees rely on strict compile-time checks, with tools like Miri used to detect UB during testing. Prior to this, Bun’s development had not reported such fundamental issues. The recent reports emerged from community members running Miri tests, which flagged critical errors in the new codebase. This is the first known instance where a significant Rust rewrite in Bun has failed core static analysis checks, raising questions about the correctness of the implementation.

“The error indicates that the code is performing invalid operations that lead to undefined behavior, even though it is marked as safe Rust. This suggests a bug in the implementation.”

— Rust developer community member

“We are investigating the Miri failures and working to understand whether these are isolated issues or indicate deeper problems in our codebase.”

— Bun project lead

Secure Coding in Rust: Preventing Memory Bugs and Writing Safe Networked Software (Rust Development for Real-World Applications)

Secure Coding in Rust: Preventing Memory Bugs and Writing Safe Networked Software (Rust Development for Real-World Applications)

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

What Remains Unclear

It remains unclear how widespread the UB issues are across Bun’s new Rust codebase or whether they are confined to specific modules. The full extent of potential security implications is still under review, and the developers have not yet released a patch or detailed technical report addressing the problem.

Amazon

Rust unsafe code detection software

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

What’s Next

The Bun team is expected to conduct further static and dynamic analysis, including more comprehensive Miri testing. A patch or update addressing these issues may be released within the next few weeks. Community members are advised to monitor official channels for updates and avoid deploying the current Rust rewrite in production environments until the issues are resolved.

Amazon

Miri Rust interpreter

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 that interprets code to detect undefined behavior at compile time. Passing Miri checks is crucial for ensuring memory safety and correctness in Rust programs.

Does this mean Bun’s Rust rewrite is unsafe?

Not necessarily. The failure indicates potential UB in code marked as safe Rust, which violates Rust’s guarantees. The developers are investigating whether these are isolated issues or indicative of deeper problems.

Should I avoid using Bun’s Rust version now?

Yes. Given the current unresolved issues, it is advisable to refrain from deploying Bun’s Rust-based components in production until further updates are provided.

Will this affect Bun’s overall stability?

If the issues are widespread, they could impact stability and security. The Bun team is working to clarify and fix the problems.

You May Also Like

First public macOS kernel memory corruption exploit on Apple M5

Researchers reveal the first public kernel memory corruption exploit on Apple M5 silicon, surviving hardware memory safety features like MIE, raising security concerns.

Firewalls are not enough against AI attacks. We need a new security mindset around information exchange. https://lantero.se/blog/ai-agenter-i-verksamheten-riskabel-effektivitet… #CyberSecurity #AISäkerhet

Experts warn traditional firewalls are insufficient against AI-driven cyber threats, calling for a fundamental shift in cybersecurity strategies.

The Home Tech Spring Cleaning Checklist

Navigating the ultimate home tech spring cleaning checklist will ensure your devices run smoothly and safely—discover essential tips you won’t want to miss.

Hackers abuse Google ads, Claude.ai chats to push Mac malware

Cybercriminals are abusing Google Ads and shared Claude.ai chats to deliver malware to Mac users, bypassing traditional detection methods in a targeted campaign.