diff options
author | 2023-03-01 18:07:21 -0300 | |
---|---|---|
committer | 2023-03-01 13:07:21 -0800 | |
commit | 56ca48ece88c0de854ec20c5e71a639fee6ccb0f (patch) | |
tree | 6161cccbd4bc5ce3f72e2ccfea9e25a8513a26cf /src | |
parent | 530cf4caf8abe4960d833efc6cce71188dea40b2 (diff) | |
download | bun-56ca48ece88c0de854ec20c5e71a639fee6ccb0f.tar.gz bun-56ca48ece88c0de854ec20c5e71a639fee6ccb0f.tar.zst bun-56ca48ece88c0de854ec20c5e71a639fee6ccb0f.zip |
fix Bun.file.arrayBuffer() segmentation fault on empty file #2248 (#2249)
* fix Bun.file.arrayBuffer() segmentation fault on empty file #2248
* cleanner this.iotask check
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/webcore/blob.zig | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index c0a865d5d..ae60ef01f 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -73,6 +73,8 @@ const PathOrBlob = union(enum) { }; pub const Blob = struct { + const bloblog = Output.scoped(.Blob, false); + pub usingnamespace JSC.Codegen.JSBlob; size: SizeType = 0, @@ -1431,9 +1433,10 @@ pub const Blob = struct { this.doClose(); } - var io_task = this.io_task.?; - this.io_task = null; - io_task.onFinish(); + if (this.io_task) |io_task| { + io_task.onFinish(); + this.io_task = null; + } } fn resolveSize(this: *ReadFile, fd: bun.FileDescriptor) void { @@ -1655,9 +1658,10 @@ pub const Blob = struct { this.doClose(); } - var io_task = this.io_task.?; - this.io_task = null; - io_task.onFinish(); + if (this.io_task) |io_task| { + io_task.onFinish(); + this.io_task = null; + } } fn runWithFD(this: *WriteFile, fd: bun.FileDescriptor) void { @@ -2825,6 +2829,8 @@ pub const Blob = struct { } pub fn doReadFile(this: *Blob, comptime Function: anytype, global: *JSGlobalObject) JSValue { + bloblog("doReadFile", .{}); + const Handler = NewReadFileHandler(Function); var promise = JSPromise.create(global); @@ -2849,6 +2855,7 @@ pub const Blob = struct { ) catch unreachable; var read_file_task = Store.ReadFile.ReadFileTask.createOnJSThread(bun.default_allocator, global, file_read) catch unreachable; read_file_task.schedule(); + bloblog("doReadFile: read_file_task scheduled", .{}); return promise_value; } @@ -3009,12 +3016,13 @@ pub const Blob = struct { } pub fn toArrayBuffer(this: *Blob, global: *JSGlobalObject, comptime lifetime: Lifetime) JSValue { + bloblog("toArrayBuffer", .{}); if (this.needsToReadFile()) { return this.doReadFile(toArrayBufferWithBytes, global); } var view_ = this.sharedView(); - + bloblog("sharedView {d}", .{view_.len}); if (view_.len == 0) return JSC.ArrayBuffer.create(global, "", .ArrayBuffer); |