| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1cdcab0 commit 896eaf6
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1474,6 +1474,11 @@ Used when a given value is out of the accepted range. | |||
| 1474 | 1474 | Used when an attempt is made to use a `zlib` object after it has already been | |
| 1475 | 1475 | closed. | |
| 1476 | 1476 | ||
| 1477 | + <a id="ERR_ZLIB_INITIALIZATION_FAILED"></a> | ||
| 1478 | + ### ERR_ZLIB_INITIALIZATION_FAILED | ||
| 1479 | + | ||
| 1480 | + Used when creation of a [`zlib`][] object fails due to incorrect configuration. | ||
| 1481 | + | ||
| 1477 | 1482 | [`--force-fips`]: cli.html#cli_force_fips | |
| 1478 | 1483 | [`crypto.timingSafeEqual()`]: crypto.html#crypto_crypto_timingsafeequal_a_b | |
| 1479 | 1484 | [`dgram.createSocket()`]: dgram.html#dgram_dgram_createsocket_options_callback | |
@@ -1515,3 +1520,4 @@ closed. | |||
| 1515 | 1520 | [try-catch]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch | |
| 1516 | 1521 | [vm]: vm.html | |
| 1517 | 1522 | [WHATWG Supported Encodings]: util.html#util_whatwg_supported_encodings | |
| 1523 | + [`zlib`]: zlib.html | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -364,6 +364,7 @@ E('ERR_VALUE_OUT_OF_RANGE', (start, end, value) => { | |||
| 364 | 364 | return `The value of "${start}" must be ${end}. Received "${value}"`; | |
| 365 | 365 | }); | |
| 366 | 366 | E('ERR_ZLIB_BINDING_CLOSED', 'zlib binding closed'); | |
| 367 | + E('ERR_ZLIB_INITIALIZATION_FAILED', 'Initialization failed'); | ||
| 367 | 368 | ||
| 368 | 369 | function invalidArgType(name, expected, actual) { | |
| 369 | 370 | internalAssert(name, 'name is required'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -161,6 +161,12 @@ function Zlib(opts, mode) { | |||
| 161 | 161 | var memLevel = Z_DEFAULT_MEMLEVEL; | |
| 162 | 162 | var strategy = Z_DEFAULT_STRATEGY; | |
| 163 | 163 | var dictionary; | |
| 164 | + | ||
| 165 | + if (typeof mode !== 'number') | ||
| 166 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'mode', 'number'); | ||
| 167 | + if (mode < DEFLATE || mode > UNZIP) | ||
| 168 | + throw new errors.RangeError('ERR_OUT_OF_RANGE', 'mode'); | ||
| 169 | + | ||
| 164 | 170 | if (opts) { | |
| 165 | 171 | chunkSize = opts.chunkSize; | |
| 166 | 172 | if (chunkSize !== undefined && chunkSize === chunkSize) { | |
@@ -258,8 +264,15 @@ function Zlib(opts, mode) { | |||
| 258 | 264 | this._hadError = false; | |
| 259 | 265 | this._writeState = new Uint32Array(2); | |
| 260 | 266 | ||
| 261 | - this._handle.init(windowBits, level, memLevel, strategy, this._writeState, | ||
| 262 | - processCallback, dictionary); | ||
| 267 | + if (!this._handle.init(windowBits, | ||
| 268 | + level, | ||
| 269 | + memLevel, | ||
| 270 | + strategy, | ||
| 271 | + this._writeState, | ||
| 272 | + processCallback, | ||
| 273 | + dictionary)) { | ||
| 274 | + throw new errors.Error('ERR_ZLIB_INITIALIZATION_FAILED'); | ||
| 275 | + } | ||
| 263 | 276 | ||
| 264 | 277 | this._outBuffer = Buffer.allocUnsafe(chunkSize); | |
| 265 | 278 | this._outOffset = 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -418,16 +418,8 @@ class ZCtx : public AsyncWrap { | |||
| 418 | 418 | ||
| 419 | 419 | static void New(const FunctionCallbackInfo<Value>& args) { | |
| 420 | 420 | Environment* env = Environment::GetCurrent(args); | |
| 421 | - | ||
| 422 | - if (args.Length() < 1 || !args[0]->IsInt32()) { | ||
| 423 | - return env->ThrowTypeError("Bad argument"); | ||
| 424 | - } | ||
| 421 | + CHECK(args[0]->IsInt32()); | ||
| 425 | 422 | node_zlib_mode mode = static_cast<node_zlib_mode>(args[0]->Int32Value()); | |
| 426 | - | ||
| 427 | - if (mode < DEFLATE || mode > UNZIP) { | ||
| 428 | - return env->ThrowTypeError("Bad argument"); | ||
| 429 | - } | ||
| 430 | - | ||
| 431 | 423 | new ZCtx(env, args.This(), mode); | |
| 432 | 424 | } | |
| 433 | 425 | ||
@@ -476,9 +468,14 @@ class ZCtx : public AsyncWrap { | |||
| 476 | 468 | memcpy(dictionary, dictionary_, dictionary_len); | |
| 477 | 469 | } | |
| 478 | 470 | ||
| 479 | - Init(ctx, level, windowBits, memLevel, strategy, write_result, | ||
| 480 | - write_js_callback, dictionary, dictionary_len); | ||
| 471 | + bool ret = Init(ctx, level, windowBits, memLevel, strategy, write_result, | ||
| 472 | + write_js_callback, dictionary, dictionary_len); | ||
| 473 | + if (!ret) goto end; | ||
| 474 | + | ||
| 481 | 475 | SetDictionary(ctx); | |
| 476 | + | ||
| 477 | + end: | ||
| 478 | + return args.GetReturnValue().Set(ret); | ||
| 482 | 479 | } | |
| 483 | 480 | ||
| 484 | 481 | static void Params(const FunctionCallbackInfo<Value>& args) { | |
@@ -495,7 +492,7 @@ class ZCtx : public AsyncWrap { | |||
| 495 | 492 | SetDictionary(ctx); | |
| 496 | 493 | } | |
| 497 | 494 | ||
| 498 | - static void Init(ZCtx *ctx, int level, int windowBits, int memLevel, | ||
| 495 | + static bool Init(ZCtx *ctx, int level, int windowBits, int memLevel, | ||
| 499 | 496 | int strategy, uint32_t* write_result, | |
| 500 | 497 | Local<Function> write_js_callback, char* dictionary, | |
| 501 | 498 | size_t dictionary_len) { | |
@@ -561,11 +558,12 @@ class ZCtx : public AsyncWrap { | |||
| 561 | 558 | ctx->dictionary_ = nullptr; | |
| 562 | 559 | } | |
| 563 | 560 | ctx->mode_ = NONE; | |
| 564 | - ctx->env()->ThrowError("Init error"); | ||
| 561 | + return false; | ||
| 565 | 562 | } | |
| 566 | 563 | ||
| 567 | 564 | ctx->write_result_ = write_result; | |
| 568 | 565 | ctx->write_js_callback_.Reset(ctx->env()->isolate(), write_js_callback); | |
| 566 | + return true; | ||
| 569 | 567 | } | |
| 570 | 568 | ||
| 571 | 569 | static void SetDictionary(ZCtx* ctx) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,9 +11,13 @@ const zlib = require('zlib'); | |||
| 11 | 11 | // no such rejection which is the reason for the version check below | |
| 12 | 12 | // (http://zlib.net/ChangeLog.txt). | |
| 13 | 13 | if (!/^1\.2\.[0-8]$/.test(process.versions.zlib)) { | |
| 14 | - assert.throws(() => { | ||
| 15 | - zlib.createDeflateRaw({ windowBits: 8 }); | ||
| 16 | - }, /^Error: Init error$/); | ||
| 14 | + common.expectsError( | ||
| 15 | + () => zlib.createDeflateRaw({ windowBits: 8 }), | ||
| 16 | + { | ||
| 17 | + code: 'ERR_ZLIB_INITIALIZATION_FAILED', | ||
| 18 | + type: Error, | ||
| 19 | + message: 'Initialization failed' | ||
| 20 | + }); | ||
| 17 | 21 | } | |
| 18 | 22 | ||
| 19 | 23 | // Regression tests for bugs in the validation logic. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments