Skip to content

Commit

Permalink
fixup! zlib
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Sep 2, 2018
1 parent 58156f9 commit 0bf15c5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/node_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uint32>()->Value();
Environment* env = ctx->env();
Local<Context> context = env->context();

unsigned int flush;
if (!args[0]->Uint32Value(context).To(&flush)) return;

if (flush != Z_NO_FLUSH &&
flush != Z_PARTIAL_FLUSH &&
Expand All @@ -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
Expand All @@ -182,18 +185,18 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
} else {
CHECK(Buffer::HasInstance(args[1]));
Local<Object> in_buf;
in_buf = args[1]->ToObject(env->context()).ToLocalChecked();
in_off = args[2].As<Uint32>()->Value();
in_len = args[3].As<Uint32>()->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<Bytef *>(Buffer::Data(in_buf) + in_off);
}

CHECK(Buffer::HasInstance(args[4]));
Local<Object> out_buf = args[4]->ToObject(env->context()).ToLocalChecked();
in_off = args[2].As<Uint32>()->Value();
in_len = args[3].As<Uint32>()->Value();
Local<Object> 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<Bytef *>(Buffer::Data(out_buf) + out_off);

Expand Down

0 comments on commit 0bf15c5

Please sign in to comment.