diff --git a/src/runtime/webcore/Blob.zig b/src/runtime/webcore/Blob.zig index 6cf5c0475545..62fbf8c8f0e5 100644 --- a/src/runtime/webcore/Blob.zig +++ b/src/runtime/webcore/Blob.zig @@ -2975,7 +2975,11 @@ pub fn getWriter( if (arguments.len > 0 and arguments.ptr[0].isObject()) { stream_start = try jsc.WebCore.streams.Start.fromJSWithTag(globalThis, arguments[0], .FileSink); - stream_start.FileSink.input_path = input_path; + if (stream_start == .FileSink) { + stream_start.FileSink.input_path = input_path; + } else { + stream_start = .{ .FileSink = .{ .input_path = input_path } }; + } } switch (sink.start(stream_start)) { diff --git a/test/js/bun/util/filesink.test.ts b/test/js/bun/util/filesink.test.ts index 736e5b085731..0203d069fcac 100644 --- a/test/js/bun/util/filesink.test.ts +++ b/test/js/bun/util/filesink.test.ts @@ -268,3 +268,17 @@ it.skipIf(!isPosix)("does not leak native FileSink when a pending write fails (E // more than that indicates a native leak. expect(fileSinkInternals.liveCount()).toBeLessThanOrEqual(baseline + 1); }); + +describe("Bun.file().writer() with invalid options", () => { + it.each([ + ["non-string path", { path: 123 }], + ["non-integer fd", { fd: "notanint" }], + ["arbitrary object", Bun], + ])("does not crash with %s", async (_, options) => { + const path = join(tmpdirSync(), "filesink-invalid-options.txt"); + const writer = Bun.file(path).writer(options as any); + writer.write("hello"); + await writer.end(); + expect(await Bun.file(path).text()).toBe("hello"); + }); +});