Skip to content

Commit defbc2e

Browse files
himself65addaleax
authored andcommitted
fs: fix fs.read when passing null value
PR-URL: #32479 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
1 parent fb254d2 commit defbc2e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/fs.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,12 @@ function read(fd, buffer, offset, length, position, callback) {
484484
callback = offset;
485485
}
486486

487-
buffer = options.buffer || Buffer.alloc(16384);
488-
offset = options.offset || 0;
489-
length = options.length || buffer.length;
490-
position = options.position;
487+
({
488+
buffer = Buffer.alloc(16384),
489+
offset = 0,
490+
length = buffer.length,
491+
position
492+
} = options);
491493
}
492494

493495
validateBuffer(buffer);

test/parallel/test-fs-read.js

+8
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ assert.throws(
8080
}
8181
);
8282

83+
['buffer', 'offset', 'length'].forEach((option) =>
84+
assert.throws(
85+
() => fs.read(fd, {
86+
[option]: null
87+
}),
88+
`not throws when options.${option} is null`
89+
));
90+
8391
assert.throws(
8492
() => fs.read(null, Buffer.alloc(1), 0, 1, 0),
8593
{

0 commit comments

Comments
 (0)