Skip to content

Commit bb4891d

Browse files
author
Hirotaka Tagawa / wafuwafu13
authored
fs: add validateBuffer to improve error
PR-URL: #44769 Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 8ec7bfd commit bb4891d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/fs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
632632
}
633633
({
634634
offset = 0,
635-
length = buffer.byteLength - offset,
635+
length = buffer?.byteLength - offset,
636636
position = null,
637637
} = params ?? kEmptyObject);
638638
}

test/parallel/test-fs-read.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ assert.throws(
7979

8080
assert.throws(
8181
() => fs.read(fd, { buffer: null }, common.mustNotCall()),
82-
/TypeError: Cannot read properties of null \(reading 'byteLength'\)/,
82+
{ code: 'ERR_INVALID_ARG_TYPE' },
8383
'throws when options.buffer is null'
8484
);
8585

0 commit comments

Comments
 (0)