From 413fd281208f24a532c47249dec1bfc3aef2bf37 Mon Sep 17 00:00:00 2001 From: Ai Hoshino Date: Sun, 30 Jul 2023 16:18:13 +0800 Subject: Fix coredump when reading an empty file(`node:stream:createReadStream`) (#3882) * Fix coredump when reading an empty file. Close: #3607 * It seems that the fd is closed when `auto_close` is true. --- test/js/node/stream/node-stream.test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/js/node/stream/node-stream.test.js') diff --git a/test/js/node/stream/node-stream.test.js b/test/js/node/stream/node-stream.test.js index 51252a5f6..5f5b9d67a 100644 --- a/test/js/node/stream/node-stream.test.js +++ b/test/js/node/stream/node-stream.test.js @@ -41,6 +41,32 @@ describe("Readable", () => { readable.pipe(writable); }); + it("should be able to be piped via .pipe, issue #3607", done => { + const path = `${tmpdir()}/${Date.now()}.testReadStreamEmptyFile.txt`; + writeFileSync(path, ""); + const stream = createReadStream(path); + stream.on("error", err => { + done(err); + }); + + let called = false; + const writable = new Writable({ + write(chunk, encoding, callback) { + called = true; + callback(); + }, + }); + writable.on("finish", () => { + try { + expect(called).toBeFalse(); + } catch (err) { + return done(err); + } + done(); + }); + + stream.pipe(writable); + }); it("should be able to be piped via .pipe, issue #3668", done => { const path = `${tmpdir()}/${Date.now()}.testReadStream.txt`; writeFileSync(path, "12345"); -- cgit v1.2.3