@@ -49,6 +49,7 @@ using v8::Local;
49
49
using v8::Number;
50
50
using v8::Object;
51
51
using v8::String;
52
+ using v8::Uint32;
52
53
using v8::Uint32Array;
53
54
using v8::Value;
54
55
@@ -155,7 +156,11 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
155
156
156
157
CHECK_EQ (false , args[0 ]->IsUndefined () && " must provide flush value" );
157
158
158
- unsigned int flush = args[0 ]->Uint32Value ();
159
+ Environment* env = ctx->env ();
160
+ Local<Context> context = env->context ();
161
+
162
+ unsigned int flush;
163
+ if (!args[0 ]->Uint32Value (context).To (&flush)) return ;
159
164
160
165
if (flush != Z_NO_FLUSH &&
161
166
flush != Z_PARTIAL_FLUSH &&
@@ -170,8 +175,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
170
175
171
176
Bytef* in;
172
177
Bytef* out;
173
- size_t in_off, in_len, out_off, out_len;
174
- Environment* env = ctx->env ();
178
+ uint32_t in_off, in_len, out_off, out_len;
175
179
176
180
if (args[1 ]->IsNull ()) {
177
181
// just a flush
@@ -181,18 +185,18 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
181
185
} else {
182
186
CHECK (Buffer::HasInstance (args[1 ]));
183
187
Local<Object> in_buf;
184
- in_buf = args[1 ]->ToObject (env-> context () ).ToLocalChecked ();
185
- in_off = args[2 ]->Uint32Value () ;
186
- in_len = args[3 ]->Uint32Value () ;
188
+ in_buf = args[1 ]->ToObject (context).ToLocalChecked ();
189
+ if (! args[2 ]->Uint32Value (context). To (&in_off)) return ;
190
+ if (! args[3 ]->Uint32Value (context). To (&in_len)) return ;
187
191
188
192
CHECK (Buffer::IsWithinBounds (in_off, in_len, Buffer::Length (in_buf)));
189
193
in = reinterpret_cast <Bytef *>(Buffer::Data (in_buf) + in_off);
190
194
}
191
195
192
196
CHECK (Buffer::HasInstance (args[4 ]));
193
- Local<Object> out_buf = args[4 ]->ToObject (env-> context () ).ToLocalChecked ();
194
- out_off = args[5 ]->Uint32Value () ;
195
- out_len = args[6 ]->Uint32Value () ;
197
+ Local<Object> out_buf = args[4 ]->ToObject (context).ToLocalChecked ();
198
+ if (! args[5 ]->Uint32Value (context). To (&out_off)) return ;
199
+ if (! args[6 ]->Uint32Value (context). To (&out_len)) return ;
196
200
CHECK (Buffer::IsWithinBounds (out_off, out_len, Buffer::Length (out_buf)));
197
201
out = reinterpret_cast <Bytef *>(Buffer::Data (out_buf) + out_off);
198
202
@@ -438,32 +442,38 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
438
442
ZCtx* ctx;
439
443
ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Holder ());
440
444
445
+ Local<Context> context = args.GetIsolate ()->GetCurrentContext ();
446
+
441
447
// windowBits is special. On the compression side, 0 is an invalid value.
442
448
// But on the decompression side, a value of 0 for windowBits tells zlib
443
449
// to use the window size in the zlib header of the compressed stream.
444
- int windowBits = args[0 ]->Uint32Value ();
450
+ uint32_t windowBits;
451
+ if (!args[0 ]->Uint32Value (context).To (&windowBits)) return ;
452
+
445
453
if (!((windowBits == 0 ) &&
446
454
(ctx->mode_ == INFLATE ||
447
455
ctx->mode_ == GUNZIP ||
448
456
ctx->mode_ == UNZIP))) {
449
- CHECK ((windowBits >= Z_MIN_WINDOWBITS &&
450
- windowBits <= Z_MAX_WINDOWBITS) && " invalid windowBits" );
457
+ CHECK (
458
+ (windowBits >= Z_MIN_WINDOWBITS && windowBits <= Z_MAX_WINDOWBITS) &&
459
+ " invalid windowBits" );
451
460
}
452
461
453
462
int level = args[1 ]->Int32Value ();
454
463
CHECK ((level >= Z_MIN_LEVEL && level <= Z_MAX_LEVEL) &&
455
464
" invalid compression level" );
456
465
457
- int memLevel = args[2 ]->Uint32Value ();
466
+ uint32_t memLevel;
467
+ if (!args[2 ]->Uint32Value (context).To (&memLevel)) return ;
458
468
CHECK ((memLevel >= Z_MIN_MEMLEVEL && memLevel <= Z_MAX_MEMLEVEL) &&
459
- " invalid memlevel" );
460
-
461
- int strategy = args[ 3 ]-> Uint32Value () ;
462
- CHECK (( strategy == Z_FILTERED ||
463
- strategy == Z_HUFFMAN_ONLY ||
464
- strategy == Z_RLE ||
465
- strategy == Z_FIXED ||
466
- strategy == Z_DEFAULT_STRATEGY) && " invalid strategy" );
469
+ " invalid memlevel" );
470
+
471
+ uint32_t strategy;
472
+ if (!args[ 3 ]-> Uint32Value (context). To (& strategy)) return ;
473
+ CHECK ((strategy == Z_FILTERED || strategy == Z_HUFFMAN_ONLY ||
474
+ strategy == Z_RLE || strategy == Z_FIXED ||
475
+ strategy == Z_DEFAULT_STRATEGY) &&
476
+ " invalid strategy" );
467
477
468
478
CHECK (args[4 ]->IsUint32Array ());
469
479
Local<Uint32Array> array = args[4 ].As <Uint32Array>();
0 commit comments