Skip to content

Commit

Permalink
fix(Bun.file) throw OOM if read is too big (#15253)
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari authored Nov 21, 2024
1 parent 144db9c commit 0eb6a4c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/bun.js/webcore/blob/ReadFile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,15 @@ pub const ReadFileUV = struct {
this.onFinish();
return;
}

// Out of memory we can't read more than 4GB at a time (ULONG) on Windows
if (this.size > @as(usize, std.math.maxInt(bun.windows.ULONG))) {
this.errno = bun.errnoToZigErr(bun.C.E.NOMEM);
this.system_error = bun.sys.Error.fromCode(bun.C.E.NOMEM, .read).toSystemError();
this.onFinish();
return;
}
// add an extra 16 bytes to the buffer to avoid having to resize it for trailing extra data
this.buffer.ensureTotalCapacityPrecise(this.byte_store.allocator, this.size + 16) catch |err| {
this.buffer.ensureTotalCapacityPrecise(this.byte_store.allocator, @min(this.size + 16, @as(usize, std.math.maxInt(bun.windows.ULONG)))) catch |err| {
this.errno = err;
this.onFinish();
return;
Expand Down

0 comments on commit 0eb6a4c

Please sign in to comment.