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);