Inflate: use max window size by default, #174

This commit is contained in:
Vitaly Puzrin 2020-11-09 19:24:26 +03:00
parent 4e8ff8e74a
commit ec116f6f40
5 changed files with 21 additions and 2 deletions

View file

@ -101,7 +101,7 @@ const {
function Inflate(options) {
this.options = utils.assign({
chunkSize: 16384,
windowBits: 0,
windowBits: 15,
to: ''
}, options || {});

View file

@ -471,7 +471,12 @@ const inflate = (strm, flush) => {
state.mode = BAD;
break;
}
state.dmax = 1 << len;
// !!! pako patch. Force use `options.windowBits` if passed.
// Required to always use max window size by default.
state.dmax = 1 << state.wbits;
//state.dmax = 1 << len;
//Tracev((stderr, "inflate: zlib header ok\n"));
strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
state.mode = hold & 0x200 ? DICTID : TYPE;

BIN
test/fixtures/bad_wbits.deflate vendored Normal file

Binary file not shown.

1
test/fixtures/bad_wbits.txt vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -3,6 +3,8 @@
const zlib = require('zlib');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const pako = require('../index');
const { testInflate, testSamples, loadSamples } = require('./helpers');
@ -206,3 +208,14 @@ describe('Inflate with dictionary', () => {
testInflate(samples, { dictionary: dict.buffer }, { dictionary: dict });
});
});
describe('pako patches for inflate', () => {
it('Force use max window size by default', () => {
const data = fs.readFileSync(path.join(__dirname, 'fixtures/bad_wbits.deflate'));
const unpacked = fs.readFileSync(path.join(__dirname, 'fixtures/bad_wbits.txt'));
assert.deepStrictEqual(pako.inflate(data), new Uint8Array(unpacked));
});
});