mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
zlib: reject windowBits=8 when mode=GZIP
It's also handled in C++ land now, per the previous commit, but intercepting it in JS land makes for prettier error messages. PR-URL: https://github.com/nodejs/node/pull/33045 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: David Carlier <devnexen@gmail.com>
This commit is contained in:
parent
b8ed2a07d3
commit
d8a380e136
@ -613,9 +613,11 @@ function Zlib(opts, mode) {
|
||||
mode === UNZIP)) {
|
||||
windowBits = 0;
|
||||
} else {
|
||||
// `{ windowBits: 8 }` is valid for deflate but not gzip.
|
||||
const min = Z_MIN_WINDOWBITS + (mode === GZIP ? 1 : 0);
|
||||
windowBits = checkRangesOrGetDefault(
|
||||
opts.windowBits, 'options.windowBits',
|
||||
Z_MIN_WINDOWBITS, Z_MAX_WINDOWBITS, Z_DEFAULT_WINDOWBITS);
|
||||
min, Z_MAX_WINDOWBITS, Z_DEFAULT_WINDOWBITS);
|
||||
}
|
||||
|
||||
level = checkRangesOrGetDefault(
|
||||
|
@ -21,7 +21,7 @@ assert.throws(
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "options.windowBits" is out of range. It must ' +
|
||||
'be >= 8 and <= 15. Received 0'
|
||||
'be >= 9 and <= 15. Received 0'
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -28,6 +28,6 @@ const zlib = require('zlib');
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "options.windowBits" is out of range. ' +
|
||||
'It must be >= 8 and <= 15. Received 0'
|
||||
'It must be >= 9 and <= 15. Received 0'
|
||||
});
|
||||
}
|
||||
|
@ -29,9 +29,10 @@ const fixtures = require('../common/fixtures');
|
||||
|
||||
// Should not segfault.
|
||||
assert.throws(() => zlib.gzipSync(Buffer.alloc(0), { windowBits: 8 }), {
|
||||
code: 'ERR_ZLIB_INITIALIZATION_FAILED',
|
||||
name: 'Error',
|
||||
message: 'Initialization failed',
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "options.windowBits" is out of range. ' +
|
||||
'It must be >= 9 and <= 15. Received 8',
|
||||
});
|
||||
|
||||
let zlibPairs = [
|
||||
|
Loading…
Reference in New Issue
Block a user