From 4f11f8f1cd78f334b2ecce20db9b1756c1058530 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Wed, 29 Aug 2018 16:46:36 +0200 Subject: [PATCH 1/9] src: remove calls to deprecated v8 functions (Uint32Value) Remove all calls to deprecated v8 functions (here: Value::Uint32Value) inside the code (src directory only). --- src/inspector_js_api.cc | 3 ++- src/node_buffer.cc | 17 +++++++++++----- src/node_crypto.cc | 18 +++++++++++------ src/node_i18n.cc | 6 +++--- src/node_process.cc | 6 +++--- src/node_zlib.cc | 44 ++++++++++++++++++++++++----------------- src/tcp_wrap.cc | 5 +++-- src/udp_wrap.cc | 11 +++++++---- 8 files changed, 68 insertions(+), 42 deletions(-) diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index b8c78ba5ebd66d..ae7452c50ef553 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -21,6 +21,7 @@ using v8::MaybeLocal; using v8::NewStringType; using v8::Object; using v8::String; +using v8::Uint32; using v8::Value; using v8_inspector::StringBuffer; @@ -241,7 +242,7 @@ void Open(const FunctionCallbackInfo& args) { bool wait_for_connect = false; if (args.Length() > 0 && args[0]->IsUint32()) { - uint32_t port = args[0]->Uint32Value(); + uint32_t port = args[0].As()->Value()); agent->options()->host_port.port = port; } diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 9a280f7c127cc6..441833a0c4be7a 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -83,6 +83,7 @@ using v8::Maybe; using v8::MaybeLocal; using v8::Object; using v8::String; +using v8::Uint32; using v8::Uint32Array; using v8::Uint8Array; using v8::Value; @@ -567,8 +568,11 @@ void Fill(const FunctionCallbackInfo& args) { THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); SPREAD_BUFFER_ARG(args[0], ts_obj); - size_t start = args[2]->Uint32Value(); - size_t end = args[3]->Uint32Value(); + Local ctx = env->context(); + uint32_t start, end; + if (!args[2]->Uint32Value(ctx).To(&start) || + !args[3]->Uint32Value(ctx).To(&end)) + return; size_t fill_length = end - start; Local str_obj; size_t str_length; @@ -588,8 +592,11 @@ void Fill(const FunctionCallbackInfo& args) { // Then coerce everything that's not a string. if (!args[1]->IsString()) { - int value = args[1]->Uint32Value() & 255; - memset(ts_obj_data + start, value, fill_length); + uint32_t val; + if (args[1]->Uint32Value(ctx).To(&val)) { + int value = val & 255; + memset(ts_obj_data + start, value, fill_length); + } return; } @@ -1004,7 +1011,7 @@ void IndexOfNumber(const FunctionCallbackInfo& args) { THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]); SPREAD_BUFFER_ARG(args[0], ts_obj); - uint32_t needle = args[1]->Uint32Value(); + uint32_t needle = args[1].As()->Value(); int64_t offset_i64 = args[2]->IntegerValue(); bool is_forward = args[3]->IsTrue(); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 89274941aab51a..47ea4ac6390d28 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3871,7 +3871,8 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo& args) { char* buf = Buffer::Data(args[1]); ssize_t len = Buffer::Length(args[1]); - int padding = args[2]->Uint32Value(); + uint32_t padding; + if (!args[2]->Uint32Value(env->context()).To(&padding)) return; String::Utf8Value passphrase(args.GetIsolate(), args[3]); @@ -4436,8 +4437,10 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo& args) { return env->ThrowError("Failed to get ECDH public key"); int size; - point_conversion_form_t form = - static_cast(args[0]->Uint32Value()); + uint32_t val; + if (!args[0]->Uint32Value(env->context()).To(&val)) + return env->ThrowError("Failed to parse argument"); + point_conversion_form_t form = static_cast(val); size = EC_POINT_point2oct(ecdh->group_, pub, form, nullptr, 0, nullptr); if (size == 0) @@ -5052,8 +5055,10 @@ void ConvertKey(const FunctionCallbackInfo& args) { if (pub == nullptr) return env->ThrowError("Failed to convert Buffer to EC_POINT"); - point_conversion_form_t form = - static_cast(args[2]->Uint32Value()); + uint32_t val; + if (!args[2]->Uint32Value(env->context()).To(&val)) + return env->ThrowError("Failed to parse argument"); + point_conversion_form_t form = static_cast(val); int size = EC_POINT_point2oct( group.get(), pub.get(), form, nullptr, 0, nullptr); @@ -5152,7 +5157,8 @@ void InitCryptoOnce() { void SetEngine(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); CHECK(args.Length() >= 2 && args[0]->IsString()); - unsigned int flags = args[1]->Uint32Value(); + uint32_t flags; + if (!args[1]->Uint32Value(env->context()).To(&flags)) return; ClearErrorOnReturn clear_error_on_return; diff --git a/src/node_i18n.cc b/src/node_i18n.cc index e5d5c0d412dc4e..b1da26e11af1c1 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -819,9 +819,9 @@ static void GetStringWidth(const FunctionCallbackInfo& args) { bool expand_emoji_sequence = args[2]->IsTrue(); if (args[0]->IsNumber()) { - args.GetReturnValue().Set( - GetColumnWidth(args[0]->Uint32Value(), - ambiguous_as_full_width)); + uint32_t val; + if (args[0]->Uint32Value(env->context()).To(&val)) + args.GetReturnValue().Set(GetColumnWidth(val, ambiguous_as_full_width)); return; } diff --git a/src/node_process.cc b/src/node_process.cc index 8db1ab5ec0121c..087a7a773eb8c3 100644 --- a/src/node_process.cc +++ b/src/node_process.cc @@ -335,7 +335,7 @@ static const char* name_by_gid(gid_t gid) { static uid_t uid_by_name(Isolate* isolate, Local value) { if (value->IsUint32()) { - return static_cast(value->Uint32Value()); + return static_cast(value.As()->Value()); } else { Utf8Value name(isolate, value); return uid_by_name(*name); @@ -345,7 +345,7 @@ static uid_t uid_by_name(Isolate* isolate, Local value) { static gid_t gid_by_name(Isolate* isolate, Local value) { if (value->IsUint32()) { - return static_cast(value->Uint32Value()); + return static_cast(value.As()->Value()); } else { Utf8Value name(isolate, value); return gid_by_name(*name); @@ -538,7 +538,7 @@ void InitGroups(const FunctionCallbackInfo& args) { char* user; if (args[0]->IsUint32()) { - user = name_by_uid(args[0]->Uint32Value()); + user = name_by_uid(args[0].As()->Value()); must_free = true; } else { user = *arg0; diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 774d319249ce63..1981ab8aefb960 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -49,6 +49,7 @@ using v8::Local; using v8::Number; using v8::Object; using v8::String; +using v8::Uint32; using v8::Uint32Array; using v8::Value; @@ -155,7 +156,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { CHECK_EQ(false, args[0]->IsUndefined() && "must provide flush value"); - unsigned int flush = args[0]->Uint32Value(); + unsigned int flush = args[0].As()->Value(); if (flush != Z_NO_FLUSH && flush != Z_PARTIAL_FLUSH && @@ -182,8 +183,8 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { CHECK(Buffer::HasInstance(args[1])); Local in_buf; in_buf = args[1]->ToObject(env->context()).ToLocalChecked(); - in_off = args[2]->Uint32Value(); - in_len = args[3]->Uint32Value(); + in_off = args[2].As()->Value(); + in_len = args[3].As()->Value(); CHECK(Buffer::IsWithinBounds(in_off, in_len, Buffer::Length(in_buf))); in = reinterpret_cast(Buffer::Data(in_buf) + in_off); @@ -191,8 +192,8 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { CHECK(Buffer::HasInstance(args[4])); Local out_buf = args[4]->ToObject(env->context()).ToLocalChecked(); - out_off = args[5]->Uint32Value(); - out_len = args[6]->Uint32Value(); + in_off = args[2].As()->Value(); + in_len = args[3].As()->Value(); CHECK(Buffer::IsWithinBounds(out_off, out_len, Buffer::Length(out_buf))); out = reinterpret_cast(Buffer::Data(out_buf) + out_off); @@ -438,32 +439,39 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { ZCtx* ctx; ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder()); + Local context = args.GetIsolate()->GetCurrentContext(); + // windowBits is special. On the compression side, 0 is an invalid value. // But on the decompression side, a value of 0 for windowBits tells zlib // to use the window size in the zlib header of the compressed stream. - int windowBits = args[0]->Uint32Value(); + uint32_t windowBits; + bool winCheck = args[0]->Uint32Value(context).To(&windowBits); + if (!((windowBits == 0) && (ctx->mode_ == INFLATE || ctx->mode_ == GUNZIP || ctx->mode_ == UNZIP))) { - CHECK((windowBits >= Z_MIN_WINDOWBITS && - windowBits <= Z_MAX_WINDOWBITS) && "invalid windowBits"); + CHECK((windowBits >= Z_MIN_WINDOWBITS && windowBits <= Z_MAX_WINDOWBITS && + winCheck) && + "invalid windowBits"); } int level = args[1]->Int32Value(); CHECK((level >= Z_MIN_LEVEL && level <= Z_MAX_LEVEL) && "invalid compression level"); - int memLevel = args[2]->Uint32Value(); - CHECK((memLevel >= Z_MIN_MEMLEVEL && memLevel <= Z_MAX_MEMLEVEL) && - "invalid memlevel"); - - int strategy = args[3]->Uint32Value(); - CHECK((strategy == Z_FILTERED || - strategy == Z_HUFFMAN_ONLY || - strategy == Z_RLE || - strategy == Z_FIXED || - strategy == Z_DEFAULT_STRATEGY) && "invalid strategy"); + uint32_t memLevel; + bool memCheck = args[2]->Uint32Value(context).To(&memLevel); + CHECK((memLevel >= Z_MIN_MEMLEVEL && memLevel <= Z_MAX_MEMLEVEL && + memCheck) && + "invalid memlevel"); + + uint32_t strategy; + bool strategyCheck = args[3]->Uint32Value(context).To(&strategy); + CHECK((strategy == Z_FILTERED || strategy == Z_HUFFMAN_ONLY || + strategy == Z_RLE || strategy == Z_FIXED || + strategy == Z_DEFAULT_STRATEGY && strategyCheck) && + "invalid strategy"); CHECK(args[4]->IsUint32Array()); Local array = args[4].As(); diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index ab8b30e84606fb..7b544d153144c9 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -48,6 +48,7 @@ using v8::Integer; using v8::Local; using v8::Object; using v8::String; +using v8::Uint32; using v8::Value; using AsyncHooks = Environment::AsyncHooks; @@ -180,7 +181,7 @@ void TCPWrap::SetKeepAlive(const FunctionCallbackInfo& args) { args.Holder(), args.GetReturnValue().Set(UV_EBADF)); int enable = args[0]->Int32Value(); - unsigned int delay = args[1]->Uint32Value(); + unsigned int delay = args[1].As()->Value(); int err = uv_tcp_keepalive(&wrap->handle_, enable, delay); args.GetReturnValue().Set(err); } @@ -277,7 +278,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo& args) { Local req_wrap_obj = args[0].As(); node::Utf8Value ip_address(env->isolate(), args[1]); - int port = args[2]->Uint32Value(); + int port = args[2].As()->Value(); sockaddr_in addr; int err = uv_ip4_addr(*ip_address, port, &addr); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index d23c62c14ecea1..27d4c7959c3f87 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -180,8 +180,11 @@ void UDPWrap::DoBind(const FunctionCallbackInfo& args, int family) { CHECK_EQ(args.Length(), 3); node::Utf8Value address(args.GetIsolate(), args[0]); - const int port = args[1]->Uint32Value(); - const int flags = args[2]->Uint32Value(); + Local ctx = args.GetIsolate()->GetCurrentContext(); + uint32_t port, flags; + if (!args[1]->Uint32Value(ctx).To(&port) || + !args[2]->Uint32Value(ctx).To(&flags)) + return; char addr[sizeof(sockaddr_in6)]; int err; @@ -353,8 +356,8 @@ void UDPWrap::DoSend(const FunctionCallbackInfo& args, int family) { Local chunks = args[1].As(); // it is faster to fetch the length of the // array in js-land - size_t count = args[2]->Uint32Value(); - const unsigned short port = args[3]->Uint32Value(); + size_t count = args[2].As()->Value(); + const unsigned short port = args[3].As()->Value(); node::Utf8Value address(env->isolate(), args[4]); const bool have_callback = args[5]->IsTrue(); From 14afa7dcfdb699db0fa21dcfb903d3b67bc1b925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Wed, 29 Aug 2018 16:52:03 +0200 Subject: [PATCH 2/9] fixup! some nits --- src/node_buffer.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 441833a0c4be7a..4323a030b3c02c 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -564,15 +564,16 @@ void Copy(const FunctionCallbackInfo &args) { void Fill(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); + Local ctx = env->context(); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); SPREAD_BUFFER_ARG(args[0], ts_obj); - Local ctx = env->context(); - uint32_t start, end; - if (!args[2]->Uint32Value(ctx).To(&start) || - !args[3]->Uint32Value(ctx).To(&end)) - return; + CHECK(args[2]->IsUint32()); + CHECK(args[3]->IsUint32()); + + uint32_t start = args[2].As()->Value(); + uint32_t end = args[3].As()->Value(); size_t fill_length = end - start; Local str_obj; size_t str_length; @@ -1004,7 +1005,7 @@ void IndexOfBuffer(const FunctionCallbackInfo& args) { } void IndexOfNumber(const FunctionCallbackInfo& args) { - CHECK(args[1]->IsNumber()); + CHECK(args[1]->IsUint32()); CHECK(args[2]->IsNumber()); CHECK(args[3]->IsBoolean()); From ccfe17dcaa5319074481edfbc06a0515eff0c486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sat, 1 Sep 2018 20:56:36 +0200 Subject: [PATCH 3/9] fixup! always uint32 --- src/node_crypto.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 47ea4ac6390d28..d30266c479ed93 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4437,9 +4437,8 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo& args) { return env->ThrowError("Failed to get ECDH public key"); int size; - uint32_t val; - if (!args[0]->Uint32Value(env->context()).To(&val)) - return env->ThrowError("Failed to parse argument"); + CHECK(args[0]->IsUint32()); + uint32_t val = args[0].As()->Value(); point_conversion_form_t form = static_cast(val); size = EC_POINT_point2oct(ecdh->group_, pub, form, nullptr, 0, nullptr); @@ -5055,9 +5054,8 @@ void ConvertKey(const FunctionCallbackInfo& args) { if (pub == nullptr) return env->ThrowError("Failed to convert Buffer to EC_POINT"); - uint32_t val; - if (!args[2]->Uint32Value(env->context()).To(&val)) - return env->ThrowError("Failed to parse argument"); + CHECK(args[2]->IsUint32()); + uint32_t val = args[2].As()->Value(); point_conversion_form_t form = static_cast(val); int size = EC_POINT_point2oct( From b19df2ed1574e5944b685cf0608d9190fe6cfbf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 2 Sep 2018 09:42:35 +0200 Subject: [PATCH 4/9] fixup! typo --- src/inspector_js_api.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index ae7452c50ef553..18b9e610750e93 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -242,7 +242,7 @@ void Open(const FunctionCallbackInfo& args) { bool wait_for_connect = false; if (args.Length() > 0 && args[0]->IsUint32()) { - uint32_t port = args[0].As()->Value()); + uint32_t port = args[0].As()->Value(); agent->options()->host_port.port = port; } From 7cdabd57d821b736e9899d8fbaedd0ccfa0b11e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 2 Sep 2018 09:43:04 +0200 Subject: [PATCH 5/9] fixup! return-on-error --- src/node_buffer.cc | 7 +++---- src/node_i18n.cc | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 4323a030b3c02c..222f72c7033f8a 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -594,10 +594,9 @@ void Fill(const FunctionCallbackInfo& args) { // Then coerce everything that's not a string. if (!args[1]->IsString()) { uint32_t val; - if (args[1]->Uint32Value(ctx).To(&val)) { - int value = val & 255; - memset(ts_obj_data + start, value, fill_length); - } + if (!args[1]->Uint32Value(ctx).To(&val)) return; + int value = val & 255; + memset(ts_obj_data + start, value, fill_length); return; } diff --git a/src/node_i18n.cc b/src/node_i18n.cc index b1da26e11af1c1..9543ab60737912 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -820,8 +820,8 @@ static void GetStringWidth(const FunctionCallbackInfo& args) { if (args[0]->IsNumber()) { uint32_t val; - if (args[0]->Uint32Value(env->context()).To(&val)) - args.GetReturnValue().Set(GetColumnWidth(val, ambiguous_as_full_width)); + if (!args[0]->Uint32Value(env->context()).To(&val)) return; + args.GetReturnValue().Set(GetColumnWidth(val, ambiguous_as_full_width)); return; } From f8219c427e0568dd0b5cc6c5e9918c7929509feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 2 Sep 2018 11:15:39 +0200 Subject: [PATCH 6/9] fix warnings in zlib --- src/node_zlib.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 1981ab8aefb960..43de81fa4d2ee6 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -445,15 +445,15 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { // But on the decompression side, a value of 0 for windowBits tells zlib // to use the window size in the zlib header of the compressed stream. uint32_t windowBits; - bool winCheck = args[0]->Uint32Value(context).To(&windowBits); + if (!args[0]->Uint32Value(context).To(&windowBits)) return; if (!((windowBits == 0) && (ctx->mode_ == INFLATE || ctx->mode_ == GUNZIP || ctx->mode_ == UNZIP))) { - CHECK((windowBits >= Z_MIN_WINDOWBITS && windowBits <= Z_MAX_WINDOWBITS && - winCheck) && - "invalid windowBits"); + CHECK( + (windowBits >= Z_MIN_WINDOWBITS && windowBits <= Z_MAX_WINDOWBITS) && + "invalid windowBits"); } int level = args[1]->Int32Value(); @@ -461,16 +461,15 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { "invalid compression level"); uint32_t memLevel; - bool memCheck = args[2]->Uint32Value(context).To(&memLevel); - CHECK((memLevel >= Z_MIN_MEMLEVEL && memLevel <= Z_MAX_MEMLEVEL && - memCheck) && + if (!args[2]->Uint32Value(context).To(&memLevel)) return; + CHECK((memLevel >= Z_MIN_MEMLEVEL && memLevel <= Z_MAX_MEMLEVEL) && "invalid memlevel"); uint32_t strategy; - bool strategyCheck = args[3]->Uint32Value(context).To(&strategy); + if (!args[3]->Uint32Value(context).To(&strategy)) return; CHECK((strategy == Z_FILTERED || strategy == Z_HUFFMAN_ONLY || strategy == Z_RLE || strategy == Z_FIXED || - strategy == Z_DEFAULT_STRATEGY && strategyCheck) && + strategy == Z_DEFAULT_STRATEGY) && "invalid strategy"); CHECK(args[4]->IsUint32Array()); From 05aa50f5fb6c272dc20e0d6362b1aabb2fe4e94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 2 Sep 2018 11:35:29 +0200 Subject: [PATCH 7/9] fixup! revert to casting in Buffer::Fill --- src/node_buffer.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 222f72c7033f8a..dcf1e2176be5d9 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -569,11 +569,10 @@ void Fill(const FunctionCallbackInfo& args) { THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); SPREAD_BUFFER_ARG(args[0], ts_obj); - CHECK(args[2]->IsUint32()); - CHECK(args[3]->IsUint32()); - - uint32_t start = args[2].As()->Value(); - uint32_t end = args[3].As()->Value(); + uint32_t start; + if (!args[2]->Uint32Value(ctx).To(&start)) return; + uint32_t end; + if (!args[3]->Uint32Value(ctx).To(&end)) return; size_t fill_length = end - start; Local str_obj; size_t str_length; From 58156f9a30ecafd5f4350bffd341035fe7ca7b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 2 Sep 2018 11:35:56 +0200 Subject: [PATCH 8/9] fixup! coerce to uint32 before calling indexOf --- lib/buffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/buffer.js b/lib/buffer.js index e025b322f0c791..5a21732c35a798 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -772,7 +772,7 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { } else if (isUint8Array(val)) { return indexOfBuffer(buffer, val, byteOffset, encoding, dir); } else if (typeof val === 'number') { - return indexOfNumber(buffer, val, byteOffset, dir); + return indexOfNumber(buffer, val >>> 0, byteOffset, dir); } throw new ERR_INVALID_ARG_TYPE( From 0bf15c510e2c7641e0046a4d094ca5fe7bfd5247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 2 Sep 2018 11:53:49 +0200 Subject: [PATCH 9/9] fixup! zlib --- src/node_zlib.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 43de81fa4d2ee6..482375cd6169ba 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -156,7 +156,11 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { CHECK_EQ(false, args[0]->IsUndefined() && "must provide flush value"); - unsigned int flush = args[0].As()->Value(); + Environment* env = ctx->env(); + Local context = env->context(); + + unsigned int flush; + if (!args[0]->Uint32Value(context).To(&flush)) return; if (flush != Z_NO_FLUSH && flush != Z_PARTIAL_FLUSH && @@ -171,8 +175,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { Bytef* in; Bytef* out; - size_t in_off, in_len, out_off, out_len; - Environment* env = ctx->env(); + uint32_t in_off, in_len, out_off, out_len; if (args[1]->IsNull()) { // just a flush @@ -182,18 +185,18 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { } else { CHECK(Buffer::HasInstance(args[1])); Local in_buf; - in_buf = args[1]->ToObject(env->context()).ToLocalChecked(); - in_off = args[2].As()->Value(); - in_len = args[3].As()->Value(); + in_buf = args[1]->ToObject(context).ToLocalChecked(); + if (!args[2]->Uint32Value(context).To(&in_off)) return; + if (!args[3]->Uint32Value(context).To(&in_len)) return; CHECK(Buffer::IsWithinBounds(in_off, in_len, Buffer::Length(in_buf))); in = reinterpret_cast(Buffer::Data(in_buf) + in_off); } CHECK(Buffer::HasInstance(args[4])); - Local out_buf = args[4]->ToObject(env->context()).ToLocalChecked(); - in_off = args[2].As()->Value(); - in_len = args[3].As()->Value(); + Local out_buf = args[4]->ToObject(context).ToLocalChecked(); + if (!args[5]->Uint32Value(context).To(&out_off)) return; + if (!args[6]->Uint32Value(context).To(&out_len)) return; CHECK(Buffer::IsWithinBounds(out_off, out_len, Buffer::Length(out_buf))); out = reinterpret_cast(Buffer::Data(out_buf) + out_off);