-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #19686 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
1 parent
a6db640
commit 7bc5151
Showing
3 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
}); | ||
} |