Skip to content

Commit b8b8e82

Browse files
himself65addaleax
authored andcommitted
fs: fix fs.read when passing null value
PR-URL: #32479 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
1 parent 1fc19b0 commit b8b8e82

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
@@ -485,10 +485,12 @@ function read(fd, buffer, offset, length, position, callback) {
485485
callback = offset;
486486
}
487487

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

494496
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)