summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Orlenko <eaglexrlnk@gmail.com>2017-05-22 21:45:57 +0300
committerMyles Borins <myles.borins@gmail.com>2017-10-25 04:25:41 -0400
commit31bf595b9417e2e3d45e9b291d6ba263ef7e288f (patch)
tree0d6b413d3ab7a36756f92fca2294c22437e031c2
parent532a2941cb6ae8679f10b64c270d9e4518935736 (diff)
downloadnode-new-31bf595b9417e2e3d45e9b291d6ba263ef7e288f.tar.gz
zlib: fix node crashing on invalid options
This is a partial backport of semver-patch bits of 9e4660b5187d4be6a1484e705dc735c0e76ffafa. This commit fixes the Node process crashing when constructors of classes of the zlib module are given invalid options. * Throw an Error when the zlib library rejects the value of windowBits, instead of crashing with an assertion. * Treat windowBits and memLevel options consistently with other ones and don't crash when non-numeric values are given. Backport-PR-URL: https://github.com/nodejs/node/pull/14860 PR-URL: https://github.com/nodejs/node/pull/13098 Fixes: https://github.com/nodejs/node/issues/13082 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
-rw-r--r--lib/zlib.js14
-rw-r--r--src/node_zlib.cc13
2 files changed, 20 insertions, 7 deletions
diff --git a/lib/zlib.js b/lib/zlib.js
index 079c413e2f..6d77f0240e 100644
--- a/lib/zlib.js
+++ b/lib/zlib.js
@@ -373,9 +373,19 @@ function Zlib(opts, mode) {
var strategy = exports.Z_DEFAULT_STRATEGY;
if (typeof opts.strategy === 'number') strategy = opts.strategy;
- this._handle.init(opts.windowBits || exports.Z_DEFAULT_WINDOWBITS,
+ var windowBits = exports.Z_DEFAULT_WINDOWBITS;
+ if (opts.windowBits && typeof opts.windowBits === 'number') {
+ windowBits = opts.windowBits;
+ }
+
+ var memLevel = exports.Z_DEFAULT_MEMLEVEL;
+ if (opts.memLevel && typeof opts.memLevel === 'number') {
+ memLevel = opts.memLevel;
+ }
+
+ this._handle.init(windowBits,
level,
- opts.memLevel || exports.Z_DEFAULT_MEMLEVEL,
+ memLevel,
strategy,
opts.dictionary);
diff --git a/src/node_zlib.cc b/src/node_zlib.cc
index 304fbf72fe..66a6a476a7 100644
--- a/src/node_zlib.cc
+++ b/src/node_zlib.cc
@@ -469,16 +469,19 @@ class ZCtx : public AsyncWrap {
CHECK(0 && "wtf?");
}
- if (ctx->err_ != Z_OK) {
- ZCtx::Error(ctx, "Init error");
- }
-
-
ctx->dictionary_ = reinterpret_cast<Bytef *>(dictionary);
ctx->dictionary_len_ = dictionary_len;
ctx->write_in_progress_ = false;
ctx->init_done_ = true;
+
+ if (ctx->err_ != Z_OK) {
+ if (dictionary != nullptr) {
+ delete[] dictionary;
+ ctx->dictionary_ = nullptr;
+ }
+ ctx->env()->ThrowError("Init error");
+ }
}
static void SetDictionary(ZCtx* ctx) {