diff options
author | Anand Suresh <anandsuresh@gmail.com> | 2018-03-29 15:07:44 -0700 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-10 00:56:10 +0200 |
commit | 7bc5151d5ec819001d40c4b34f6921d5a7242ba8 (patch) | |
tree | 1f0f854c77380d07c16f9f972e711a11962d496d /test/parallel/test-zlib-zero-windowBits.js | |
parent | a6db6404ff200ab37b69a33fad48cb6fa73d8bc8 (diff) | |
download | android-node-v8-7bc5151d5ec819001d40c4b34f6921d5a7242ba8.tar.gz android-node-v8-7bc5151d5ec819001d40c4b34f6921d5a7242ba8.tar.bz2 android-node-v8-7bc5151d5ec819001d40c4b34f6921d5a7242ba8.zip |
zlib: fix windowBits validation to allow 0 for decompression mode
From the zlib v1.2.11 manual:
> ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
> int windowBits));
>
> ...
> windowBits can also be zero to request that inflate use the window
> size in the zlib header of the compressed stream.
The current validation of windowBits in zlib.js doesn't check for this
case.
PR-URL: https://github.com/nodejs/node/pull/19686
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test/parallel/test-zlib-zero-windowBits.js')
-rw-r--r-- | test/parallel/test-zlib-zero-windowBits.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/parallel/test-zlib-zero-windowBits.js b/test/parallel/test-zlib-zero-windowBits.js new file mode 100644 index 0000000000..a62e6148e3 --- /dev/null +++ b/test/parallel/test-zlib-zero-windowBits.js @@ -0,0 +1,33 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const zlib = require('zlib'); + + +// windowBits is a special case in zlib. On the compression side, 0 is invalid. +// On the decompression side, it indicates that zlib should use the value from +// the header of the compressed stream. +{ + const inflate = zlib.createInflate({ windowBits: 0 }); + assert(inflate instanceof zlib.Inflate); +} + +{ + const gunzip = zlib.createGunzip({ windowBits: 0 }); + assert(gunzip instanceof zlib.Gunzip); +} + +{ + const unzip = zlib.createUnzip({ windowBits: 0 }); + assert(unzip instanceof zlib.Unzip); +} + +{ + common.expectsError(() => zlib.createGzip({ windowBits: 0 }), { + code: 'ERR_OUT_OF_RANGE', + type: RangeError, + message: 'The value of "options.windowBits" is out of range. ' + + 'It must be >= 8 and <= 15. Received 0' + }); +} |