Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lib: fix fs.read when passing null value
  • Loading branch information
himself65 committed Mar 26, 2020
commit e8daf89486b5a11f3dfa3b00d9cd6b2ebaa13a61
10 changes: 6 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,12 @@ function read(fd, buffer, offset, length, position, callback) {
callback = offset;
}

buffer = options.buffer || Buffer.alloc(16384);
offset = options.offset || 0;
length = options.length || buffer.length;
position = options.position;
({
buffer = Buffer.alloc(16384),
offset = 0,
length = buffer.length,
position
} = options);
}

validateBuffer(buffer);
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-fs-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ assert.throws(
}
);

['buffer', 'offset', 'length'].forEach((option) =>
assert.throws(
() => fs.read(fd, {
[option]: null
}),
`not throws when options.${option} is null`
));

assert.throws(
() => fs.read(null, Buffer.alloc(1), 0, 1, 0),
{
Expand Down