Skip to content

Commit 8d100c2

Browse files
committed
fs: use consistent buffer array validation
This commit updates fs.writev() and fs.writevSync() to use the same validation method as filehandle.writev(). PR-URL: #29186 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3273d0e commit 8d100c2

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

lib/fs.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const {
7272
stringToFlags,
7373
stringToSymlinkType,
7474
toUnixTimestamp,
75+
validateBufferArray,
7576
validateOffsetLengthRead,
7677
validateOffsetLengthWrite,
7778
validatePath,
@@ -142,19 +143,6 @@ function maybeCallback(cb) {
142143
throw new ERR_INVALID_CALLBACK(cb);
143144
}
144145

145-
function isBuffersArray(value) {
146-
if (!Array.isArray(value))
147-
return false;
148-
149-
for (var i = 0; i < value.length; i += 1) {
150-
if (!isArrayBufferView(value[i])) {
151-
return false;
152-
}
153-
}
154-
155-
return true;
156-
}
157-
158146
// Ensure that callbacks run in the global context. Only use this function
159147
// for callbacks that are passed to the binding layer, callbacks that are
160148
// invoked from JS already run in the proper scope.
@@ -626,10 +614,7 @@ function writev(fd, buffers, position, callback) {
626614
}
627615

628616
validateInt32(fd, 'fd', 0);
629-
630-
if (!isBuffersArray(buffers)) {
631-
throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers);
632-
}
617+
validateBufferArray(buffers);
633618

634619
const req = new FSReqCallback();
635620
req.oncomplete = wrapper;
@@ -647,15 +632,11 @@ Object.defineProperty(writev, internalUtil.customPromisifyArgs, {
647632
enumerable: false
648633
});
649634

650-
// fs.writevSync(fd, buffers[, position]);
651635
function writevSync(fd, buffers, position) {
652-
653636
validateInt32(fd, 'fd', 0);
654-
const ctx = {};
637+
validateBufferArray(buffers);
655638

656-
if (!isBuffersArray(buffers)) {
657-
throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers);
658-
}
639+
const ctx = {};
659640

660641
if (typeof position !== 'number')
661642
position = null;

0 commit comments

Comments
 (0)