Skip to content

Commit

Permalink
fs: fix error when writing buffers > INT32_MAX
Browse files Browse the repository at this point in the history
This reverts c380ee6. uv_fs_write returns an
int, so it is not possible to ask it to write more than INT32_MAX.

Instead, validate 'length' is an int32 in JS to avoid the assertion failure.
  • Loading branch information
zbjornson committed May 5, 2021
1 parent efd70f4 commit 85ec0e2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/internal/fs/utils.js
Expand Up @@ -659,6 +659,8 @@ const validateOffsetLengthWrite = hideStackFrames(
if (length < 0) {
throw new ERR_OUT_OF_RANGE('length', '>= 0', length);
}

validateInt32(length, 'length', 0);
}
);

Expand Down
4 changes: 2 additions & 2 deletions src/node_file.cc
Expand Up @@ -1835,8 +1835,8 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
CHECK_LE(static_cast<uint64_t>(off_64), buffer_length);
const size_t off = static_cast<size_t>(off_64);

CHECK(IsSafeJsInt(args[3]));
const size_t len = static_cast<size_t>(args[3].As<Integer>()->Value());
CHECK(args[3]->IsInt32());
const size_t len = static_cast<size_t>(args[3].As<Int32>()->Value());
CHECK(Buffer::IsWithinBounds(off, len, buffer_length));
CHECK_LE(len, buffer_length);
CHECK_GE(off + len, off);
Expand Down

0 comments on commit 85ec0e2

Please sign in to comment.