Skip to content

Commit

Permalink
fs: add validateBuffer to improve error
Browse files Browse the repository at this point in the history
  • Loading branch information
wafuwafu13 committed Sep 24, 2022
1 parent abfeed8 commit 73aaca6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
// This is fs.read(fd, params, callback)
params = buffer;
({ buffer = Buffer.alloc(16384) } = params ?? kEmptyObject);
validateBuffer(buffer);
}
callback = offsetOrOptions;
} else {
Expand Down
6 changes: 5 additions & 1 deletion test/parallel/test-fs-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ assert.throws(

assert.throws(
() => fs.read(fd, { buffer: null }, common.mustNotCall()),
/TypeError: Cannot read properties of null \(reading 'byteLength'\)/,
{
name: 'TypeError',
message: 'The "buffer" argument must be an instance of Buffer, ' +
'TypedArray, or DataView. Received null',
},
'throws when options.buffer is null'
);

Expand Down

0 comments on commit 73aaca6

Please sign in to comment.