Skip to content

Commit

Permalink
Inflate: use max window size by default, #174
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin authored and rlidwka committed Jun 10, 2022
1 parent e52059b commit 8bbc469
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/inflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const {
function Inflate(options) {
this.options = utils.assign({
chunkSize: 16384,
windowBits: 0,
windowBits: 15,
to: ''
}, options || {});

Expand Down
7 changes: 6 additions & 1 deletion lib/zlib/inflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file added test/fixtures/bad_wbits.deflate
Binary file not shown.
1 change: 1 addition & 0 deletions test/fixtures/bad_wbits.txt

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions test/inflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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));
});
});

0 comments on commit 8bbc469

Please sign in to comment.