From 9e4660b5187d4be6a1484e705dc735c0e76ffafa Mon Sep 17 00:00:00 2001 From: Alexey Orlenko Date: Thu, 18 May 2017 12:49:08 +0300 Subject: zlib: fix node crashing on invalid options 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. * Fix bugs in the validation logic: - Don't conflate 0 and undefined when checking if a field of an options object exists. - Treat NaN and Infinity values the same way as values of invalid types instead of allowing to actually set zlib options to NaN or Infinity. 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 | 34 ++++++++++++++++++++++--------- src/node_zlib.cc | 13 +++++++----- test/parallel/test-zlib-failed-init.js | 37 ++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 test/parallel/test-zlib-failed-init.js diff --git a/doc/api/zlib.md b/doc/api/zlib.md index abfb6e2038..f889914bb0 100644 --- a/doc/api/zlib.md +++ b/doc/api/zlib.md @@ -437,6 +437,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])