mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 20:09:04 +00:00
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.
This commit is contained in:
@@ -4433,6 +4433,10 @@ pub const FileReader = struct {
|
||||
var readable_file = File{ .loop = this.globalThis().bunVM().eventLoop() };
|
||||
|
||||
const result = readable_file.start(&blob.data.file);
|
||||
if (result == .empty) {
|
||||
this.lazy_readable = .{ .empty = {} };
|
||||
return result;
|
||||
}
|
||||
if (result != .ready) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user