Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: fix fs.read when passing null value #32479

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/fs.js
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
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