Tags: oven-sh/bun
Tags
Fix integer cast truncation panic on Windows for buffers > 4GB (#21738) ## Summary This PR fixes a panic that occurs when file operations use buffers larger than 4GB on Windows. ## The Problem When calling `fs.readSync()` or `fs.writeSync()` with buffers larger than 4,294,967,295 bytes (u32::MAX), Bun panics with: ``` panic(main thread): integer cast truncated bits ``` ## Root Cause The Windows APIs `ReadFile()` and `WriteFile()` expect a `DWORD` (u32) for the buffer length parameter. The code was using `@intCast` to convert from `usize` to `u32`, which panics when the value exceeds u32::MAX. ## The Fix Changed `@intCast` to `@truncate` in four locations: 1. `sys.zig:1839` - ReadFile buffer length parameter 2. `sys.zig:1556` - WriteFile buffer length parameter 3. `bun.zig:230` - platformIOVecCreate length field 4. `bun.zig:240` - platformIOVecConstCreate length field With these changes, operations with buffers > 4GB will read/write up to 4GB at a time instead of panicking. ## Test Plan ```js // This previously caused a panic on Windows const fs = require('fs'); const fd = fs.openSync('test.txt', 'r'); const buffer = Buffer.allocUnsafe(4_294_967_296); // 4GB + 1 byte fs.readSync(fd, buffer, 0, buffer.length, 0); ``` Fixes #21699 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Jarred Sumner <[email protected]> Co-authored-by: Claude <[email protected]>
Update interactive spacing (#21156) Co-authored-by: Claude Bot <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: RiskyMH <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Jarred Sumner <[email protected]>
Fixes #20753 (#20789) Co-authored-by: Jarred-Sumner <[email protected]>
Delete .node files from bun build --compile after dlopen (#19551) Co-authored-by: 190n <[email protected]>
PreviousNext