From de45915b3483fb7e86c166e876772c6a995ce216 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Fri, 13 Oct 2017 01:10:44 -0400 Subject: [PATCH] zlib: gracefully set windowBits from 8 to 9 On 4 April 2017, Node.js versions v4.8.2 and v6.10.2 were released. These versions bumped the vendored zlib library from v1.2.8 to v1.2.11 in response to what it describes as low-severity CVEs. In zlib v1.2.9, a change was made that causes an error to be raised when a raw deflate stream is initialised with windowBits set to 8. In zlib v1.2.9, 8 become an invalid value for this parameter, and Node's zlib module will crash if you call this: ``` zlib.createDeflateRaw({windowBits: 8}) ``` On some versions this crashes Node and you cannot recover from it, while on some versions it throws an exception. The permessage-deflate library up to version v0.1.5 does make such a call with no try/catch This commit reverts to the original behavior of zlib by gracefully changed windowBits: 8 to windowBits: 9 for raw deflate streams. Original-PR-URL: https://github.com/nodejs-private/node-private/pull/95 Reviewed-By: Anna Henningsen Reviewed-By: Evan Lucas Reviewed-By: Michael Dawson Reviewed-By: Sam Roberts PR-URL: https://github.com/nodejs/node/pull/16511 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson Reviewed-By: Refael Ackermann --- doc/api/zlib.md | 10 +++++++--- lib/zlib.js | 1 + test/parallel/test-zlib-failed-init.js | 17 ----------------- test/parallel/test-zlib.js | 23 +++++++++++++++++++++++ 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/doc/api/zlib.md b/doc/api/zlib.md index 5575d03d33..96e6a0c87d 100644 --- a/doc/api/zlib.md +++ b/doc/api/zlib.md @@ -458,9 +458,13 @@ added: v0.5.8 Creates and returns a new [DeflateRaw][] object with the given [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. +*Note*: An upgrade of zlib from 1.2.8 to 1.2.11 changed behavior when windowBits +is set to 8 for raw deflate streams. zlib does not have a working implementation +of an 8-bit Window for raw deflate streams and would automatically set windowBit +to 9 if initially set to 8. Newer versions of zlib will throw an exception. +This creates a potential DOS vector, and as such the behavior ahs been reverted +in Node.js 8, 6, and 4. Node.js version 9 and higher will throw when windowBits +is set to 8. ## zlib.createGunzip([options])