Skip to content

Commit bde0837

Browse files
himself65targos
authored andcommitted
fs: fix fs.read when passing null value
PR-URL: #32479 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
1 parent 5598dd1 commit bde0837

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/fs.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,12 @@ function read(fd, buffer, offset, length, position, callback) {
481481
callback = offset;
482482
}
483483

484-
buffer = options.buffer || Buffer.alloc(16384);
485-
offset = options.offset || 0;
486-
length = options.length || buffer.length;
487-
position = options.position;
484+
({
485+
buffer = Buffer.alloc(16384),
486+
offset = 0,
487+
length = buffer.length,
488+
position
489+
} = options);
488490
}
489491

490492
validateBuffer(buffer);

test/parallel/test-fs-read.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ assert.throws(
8080
}
8181
);
8282

83+
['buffer', 'offset', 'length'].forEach((option) =>
84+
assert.throws(
85+
() => fs.read(fd, {
86+
[option]: null
87+
}),
88+
`not throws when options.${option} is null`
89+
));
90+
8391
assert.throws(
8492
() => fs.read(null, Buffer.alloc(1), 0, 1, 0),
8593
{

0 commit comments

Comments
 (0)