From 0bbda5e5aede9b264a3c6188529c9dbed1ec9719 Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Mon, 18 Mar 2019 11:27:13 -0700 Subject: fs: allow int64 offset in fs.read/readSync/fd.read Since v10.10.0, 'buf' can be any DataView, meaning the largest byteLength can be Float64Array.BYTES_PER_ELEMENT * kMaxLength = 17,179,869,176. 'offset' can now be up to 2**53 - 1. This makes it possible to tile reads into a large buffer. Breaking: now throws if read offset is not a safe int, is null or is undefined. Fixes https://github.com/nodejs/node/issues/26563 PR-URL: https://github.com/nodejs/node/pull/26572 Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater Reviewed-By: Ujjwal Sharma Reviewed-By: James M Snell Reviewed-By: Rich Trott --- src/node_file.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/node_file.cc') diff --git a/src/node_file.cc b/src/node_file.cc index 138848c49d..5bd0237e7b 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1851,7 +1851,7 @@ static void WriteString(const FunctionCallbackInfo& args) { * * 0 fd int32. file descriptor * 1 buffer instance of Buffer - * 2 offset int32. offset to start reading into inside buffer + * 2 offset int64. offset to start reading into inside buffer * 3 length int32. length to read * 4 position int64. file position - -1 for current position */ @@ -1869,15 +1869,17 @@ static void Read(const FunctionCallbackInfo& args) { char* buffer_data = Buffer::Data(buffer_obj); size_t buffer_length = Buffer::Length(buffer_obj); - CHECK(args[2]->IsInt32()); - const size_t off = static_cast(args[2].As()->Value()); - CHECK_LT(off, buffer_length); + CHECK(IsSafeJsInt(args[2])); + const int64_t off_64 = args[2].As()->Value(); + CHECK_GE(off_64, 0); + CHECK_LT(static_cast(off_64), buffer_length); + const size_t off = static_cast(off_64); CHECK(args[3]->IsInt32()); const size_t len = static_cast(args[3].As()->Value()); CHECK(Buffer::IsWithinBounds(off, len, buffer_length)); - CHECK(args[4]->IsNumber()); + CHECK(IsSafeJsInt(args[4])); const int64_t pos = args[4].As()->Value(); char* buf = buffer_data + off; -- cgit v1.2.3