-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix integer overflow in ReadFile buffer capacity computation #28849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -381,14 +381,15 @@ | |
| this.onFinish(); | ||
| return; | ||
| } | ||
|
|
||
| // add an extra 16 bytes to the buffer to avoid having to resize it for trailing extra data | ||
| if (!this.could_block or (this.size > 0 and this.size != Blob.max_size)) | ||
| this.buffer = std.ArrayListUnmanaged(u8).initCapacity(bun.default_allocator, this.size + 16) catch |err| { | ||
| this.buffer = std.ArrayListUnmanaged(u8).initCapacity(bun.default_allocator, this.size +| 16) catch |err| { | ||
| this.errno = err; | ||
| this.system_error = bun.sys.Error.fromCode(bun.sys.E.NOMEM, .read).toSystemError(); | ||
| this.onFinish(); | ||
| return; | ||
| }; | ||
|
Check notice on line 392 in src/bun.js/webcore/blob/read_file.zig
|
||
|
Comment on lines
384
to
392
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟣 This PR correctly makes the Extended reasoning...What the bug is and how it manifests
bun.handleOom(this.buffer.ensureTotalCapacityPrecise(bun.default_allocator, read.len));
// or
bun.handleOom(this.buffer.ensureUnusedCapacity(bun.default_allocator, read.len));
The specific code path that triggers it When reading a streaming/blocking source like Why existing code does not prevent it The PR's graceful OOM handling is applied only to What the impact would be An observable behavioral asymmetry exists post-merge: a user who slices a streaming file with a large offset (e.g., Step-by-step proof
How to fix it Replace the two |
||
| this.read_off = 0; | ||
|
|
||
| // If it's not a regular file, it might be something | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.