Skip to content

Commit

Permalink
fs: fix fs.read when passing null value
Browse files Browse the repository at this point in the history
PR-URL: #32479
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
  • Loading branch information
himself65 authored and targos committed Apr 28, 2020
1 parent 5598dd1 commit bde0837
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/fs.js
Expand Up @@ -481,10 +481,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
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

0 comments on commit bde0837

Please sign in to comment.