diff --git a/src/runtime/webcore/Blob.zig b/src/runtime/webcore/Blob.zig index 6cf5c0475545..9e01f7528134 100644 --- a/src/runtime/webcore/Blob.zig +++ b/src/runtime/webcore/Blob.zig @@ -2974,8 +2974,12 @@ 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; + var parsed = try jsc.WebCore.streams.Start.fromJSWithTag(globalThis, arguments[0], .FileSink); + if (parsed == .FileSink) { + parsed.FileSink.input_path.deinit(); + parsed.FileSink.input_path = input_path; + stream_start = parsed; + } } 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..e55477963709 100644 --- a/test/js/bun/util/filesink.test.ts +++ b/test/js/bun/util/filesink.test.ts @@ -207,6 +207,18 @@ it("write result is not cumulative", async () => { await util.promisify(fs.close)(fd); }); +it("writer() does not crash when options object has a non-string 'path' property", async () => { + const x = tmpdirSync(); + const dest = path.join(x, "test.txt"); + const file = Bun.file(dest); + const options = {}; + Object.defineProperty(options, "path", { enumerable: true, value: Uint32Array }); + const writer = file.writer(options); + await writer.write("hello"); + await writer.end(); + expect(await Bun.file(dest).text()).toBe("hello"); +}); + if (isWindows) { it("ENOENT, Windows", () => { expect(() => Bun.file("A:\\this-does-not-exist.txt").writer()).toThrow(