diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 3b7754292821f3..322b1519ef2807 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -659,6 +659,8 @@ const validateOffsetLengthWrite = hideStackFrames( if (length < 0) { throw new ERR_OUT_OF_RANGE('length', '>= 0', length); } + + validateInt32(length, 'length', 0); } ); diff --git a/src/node_file.cc b/src/node_file.cc index b8902f6b348eca..d3bcb8fbd804c7 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1835,8 +1835,8 @@ static void WriteBuffer(const FunctionCallbackInfo& args) { CHECK_LE(static_cast(off_64), buffer_length); const size_t off = static_cast(off_64); - CHECK(IsSafeJsInt(args[3])); - const size_t len = static_cast(args[3].As()->Value()); + CHECK(args[3]->IsInt32()); + const size_t len = static_cast(args[3].As()->Value()); CHECK(Buffer::IsWithinBounds(off, len, buffer_length)); CHECK_LE(len, buffer_length); CHECK_GE(off + len, off);