Skip to content

Commit 82eeadb

Browse files
cjihrigtargos
authored andcommitted
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 81f3eb5 commit 82eeadb

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

lib/fs.js

+4-23
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.
@@ -610,10 +598,7 @@ function writev(fd, buffers, position, callback) {
610598
}
611599

612600
validateInt32(fd, 'fd', 0);
613-
614-
if (!isBuffersArray(buffers)) {
615-
throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers);
616-
}
601+
validateBufferArray(buffers);
617602

618603
const req = new FSReqCallback();
619604
req.oncomplete = wrapper;
@@ -631,15 +616,11 @@ Object.defineProperty(writev, internalUtil.customPromisifyArgs, {
631616
enumerable: false
632617
});
633618

634-
// fs.writevSync(fd, buffers[, position]);
635619
function writevSync(fd, buffers, position) {
636-
637620
validateInt32(fd, 'fd', 0);
638-
const ctx = {};
621+
validateBufferArray(buffers);
639622

640-
if (!isBuffersArray(buffers)) {
641-
throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers);
642-
}
623+
const ctx = {};
643624

644625
if (typeof position !== 'number')
645626
position = null;

0 commit comments

Comments
 (0)