Files
bun.sh/src
robobun ba6e84fecd fix(compile): seek to start of file before EXDEV cross-device copy (#26883)
## What does this PR do?

Fixes `bun build --compile` producing an all-zeros binary when the
output directory is on a different filesystem than the temp directory.
This is common in Docker containers, Gitea runners, and other
environments using overlayfs.

## Problem

When `inject()` finishes writing the modified executable to the temp
file, the file descriptor's offset is at EOF. If the subsequent
`renameat()` to the output path fails with `EXDEV` (cross-device — the
temp file and output dir are on different filesystems), the code falls
back to `copyFileZSlowWithHandle()`, which:

1. Calls `fallocate()` to pre-allocate the output file to the correct
size (filled with zeros)
2. Calls `bun.copyFile(in_handle, out_handle)` — but `in_handle`'s
offset is at EOF
3. `copy_file_range` / `sendfile` / `read` all use the current file
offset (EOF), read 0 bytes, and return immediately
4. Result: output file is the correct size but entirely zeros

This explains user reports of `bun build --compile
--target=bun-darwin-arm64` producing invalid binaries that `file`
identifies as "data" rather than a Mach-O executable.

## Fix

Seek the input fd to offset 0 in `copyFileZSlowWithHandle` before
calling `bun.copyFile`.

## How did you verify your code works?

- `bun bd` compiles successfully
- `bun bd test test/bundler/bun-build-compile.test.ts` — 6/6 pass
- Added tests that verify compiled binaries have valid executable
headers and produce correct output
- Manually verified cross-compilation: `bun build --compile
--target=bun-darwin-arm64` produces a valid Mach-O binary

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-10 22:32:31 -08:00
..
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2026-02-03 22:18:40 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-20 20:56:02 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-12-25 14:00:58 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2026-01-07 12:33:21 -08:00
2025-11-10 14:38:26 -08:00
2025-11-20 20:56:02 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2026-01-30 01:38:45 -08:00
2025-12-01 21:59:11 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00
2025-11-10 14:38:26 -08:00