From e8f73601c0e3c6a5f44037e52bd5d4a79d536727 Mon Sep 17 00:00:00 2001 From: robobun Date: Tue, 10 Feb 2026 23:04:46 -0800 Subject: [PATCH] fix(compile): use remaining buffer in standalone POSIX write loop (#26882) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What does this PR do? Fixes the write loop in `StandaloneModuleGraph.inject()` for POSIX targets (the `else` branch handling ELF/Linux standalone binaries) to pass `remain` instead of `bytes` to `Syscall.write()`. ## Problem The write loop that appends the bundled module graph to the end of the executable uses a standard partial-write retry pattern, but passes the full `bytes` buffer on every iteration instead of the remaining portion: ```zig var remain = bytes; while (remain.len > 0) { switch (Syscall.write(cloned_executable_fd, bytes)) { // bug: should be 'remain' .result => |written| remain = remain[written..], ... } } ``` If a partial write occurs, the next iteration re-writes from the start of the buffer instead of continuing where it left off, corrupting the output binary. The analogous read loop elsewhere in the same file already correctly uses `remain`. ## Fix One-character change: `bytes` → `remain` in the `Syscall.write()` call. ## How did you verify your code works? - `bun bd` compiles successfully - `bun bd test test/bundler/bun-build-compile.test.ts` — 4/4 pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Bot Co-authored-by: Claude Co-authored-by: Alistair Smith --- src/StandaloneModuleGraph.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StandaloneModuleGraph.zig b/src/StandaloneModuleGraph.zig index 3985a6aee6..dd63115ee9 100644 --- a/src/StandaloneModuleGraph.zig +++ b/src/StandaloneModuleGraph.zig @@ -935,7 +935,7 @@ pub const StandaloneModuleGraph = struct { var remain = bytes; while (remain.len > 0) { - switch (Syscall.write(cloned_executable_fd, bytes)) { + switch (Syscall.write(cloned_executable_fd, remain)) { .result => |written| remain = remain[written..], .err => |err| { Output.prettyErrorln("error: failed to write to temporary file\n{f}", .{err});