diff options
author | Anand Suresh <anandsuresh@gmail.com> | 2018-03-30 01:07:44 +0300 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-10 01:56:10 +0300 |
commit | 7bc5151d5ec819001d40c4b34f6921d5a7242ba8 (patch) | |
tree | 1f0f854c77380d07c16f9f972e711a11962d496d /src/node_zlib.cc | |
parent | a6db6404ff200ab37b69a33fad48cb6fa73d8bc8 (diff) |
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 'src/node_zlib.cc')
-rw-r--r-- | src/node_zlib.cc | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 500a62a52bf..4367d043d25 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -438,9 +438,17 @@ class ZCtx : public AsyncWrap { ZCtx* ctx; ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder()); + // windowBits is special. On the compression side, 0 is an invalid value. + // But on the decompression side, a value of 0 for windowBits tells zlib + // to use the window size in the zlib header of the compressed stream. int windowBits = args[0]->Uint32Value(); - CHECK((windowBits >= Z_MIN_WINDOWBITS && windowBits <= Z_MAX_WINDOWBITS) && - "invalid windowBits"); + if (!((windowBits == 0) && + (ctx->mode_ == INFLATE || + ctx->mode_ == GUNZIP || + ctx->mode_ == UNZIP))) { + CHECK((windowBits >= Z_MIN_WINDOWBITS && + windowBits <= Z_MAX_WINDOWBITS) && "invalid windowBits"); + } int level = args[1]->Int32Value(); CHECK((level >= Z_MIN_LEVEL && level <= Z_MAX_LEVEL) && |