From 2a8ef7a1aff5428875a0092d81eb50259020f5a8 Mon Sep 17 00:00:00 2001 From: Alexey Orlenko Date: Mon, 22 May 2017 21:45:57 +0300 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Sakthipriyan Vairamani --- doc/api/zlib.md | 4 ++++ lib/zlib.js | 14 ++++++++++++-- src/node_zlib.cc | 13 ++++++++----- test/parallel/test-zlib-failed-init.js | 13 +++++++++++++ 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 test/parallel/test-zlib-failed-init.js diff --git a/doc/api/zlib.md b/doc/api/zlib.md index 8e5f14621b9dd1..6947b2047eae02 100644 --- a/doc/api/zlib.md +++ b/doc/api/zlib.md @@ -373,6 +373,10 @@ added: v0.5.8 Returns a new [DeflateRaw][] object with an [options][]. +*Note*: The zlib library rejects requests for 256-byte windows (i.e., +`{ windowBits: 8 }` in `options`). An `Error` will be thrown when creating a +[DeflateRaw][] object with this specific value of the `windowBits` option. + ## zlib.createGunzip([options])