fs: add validateBuffer to improve error

PR-URL: https://github.com/nodejs/node/pull/44769
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Hirotaka Tagawa / wafuwafu13 2022-09-28 17:44:39 +09:00 committed by GitHub
parent 8ec7bfd9c5
commit bb4891d8d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -632,7 +632,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
}
({
offset = 0,
length = buffer.byteLength - offset,
length = buffer?.byteLength - offset,
position = null,
} = params ?? kEmptyObject);
}

View File

@ -79,7 +79,7 @@ assert.throws(
assert.throws(
() => fs.read(fd, { buffer: null }, common.mustNotCall()),
/TypeError: Cannot read properties of null \(reading 'byteLength'\)/,
{ code: 'ERR_INVALID_ARG_TYPE' },
'throws when options.buffer is null'
);