mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
Closes #8254 Fixes a data corruption bug in `Bun.write()` where files larger than 2GB would have chunks skipped resulting in corrupted output with missing data. The `doWriteLoop` had an issue where it would essentially end up offsetting twice every 2GB chunks: - it first sliced the buffer by `total_written`: ```remain = remain[@min(this.total_written, remain.len)..]``` - it would then increment `bytes_blob.offset`: `this.bytes_blob.offset += @truncate(wrote)` but because `sharedView()` already uses the blob offset `slice_ = slice_[this.offset..]` it would end up doubling the offset. In a local reproduction writing a 16GB file with each 2GB chunk filled with incrementing values `[1, 2, 3, 4, 5, 6, 7, 8]`, the buggy version produced: `[1, 3, 5, 7, …]`, skipping every other chunk. The fix is to simply remove the redundant manual offset and rely only on `total_written` to track write progress.