Skip to content

Commit

Permalink
test: add tests for reproducing #5852
Browse files Browse the repository at this point in the history
Add test files that reliably reproduce #5852. The gzipped file
in test/fixtures/pseudo-multimember-gzip.gz contains the gzip
magic bytes exactly at the position that node encounters after having
read a single block, leading it to believe that a new data
member is starting.
  • Loading branch information
addaleax committed Mar 23, 2016
1 parent 387b6b4 commit 2dd5945
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Binary file added test/fixtures/pseudo-multimember-gzip.gz
Binary file not shown.
Binary file added test/fixtures/pseudo-multimember-gzip.z
Binary file not shown.
22 changes: 22 additions & 0 deletions test/parallel/test-zlib-from-concatenated-gzip.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
const common = require('../common');
const assert = require('assert');
const zlib = require('zlib');
const path = require('path');
const fs = require('fs');

const data = Buffer.concat([
zlib.gzipSync('abc'),
Expand All @@ -16,3 +18,23 @@ zlib.gunzip(data, common.mustCall((err, result) => {
assert.ifError(err);
assert.equal(result, 'abcdef', 'result should match original string');
}));

// files that have the "right" magic bytes for starting a new gzip member
// in the middle of themselves, even if they are part of a single
// regularly compressed member
const pmmFileZlib = path.join(common.fixturesDir, 'pseudo-multimember-gzip.z');
const pmmFileGz = path.join(common.fixturesDir, 'pseudo-multimember-gzip.gz');

const pmmExpected = zlib.inflateSync(fs.readFileSync(pmmFileZlib));
const pmmResultBuffers = [];

fs.createReadStream(pmmFileGz)
.pipe(zlib.createGunzip())
.on('error', (err) => {
assert.ifError(err);
})
.on('data', (data) => pmmResultBuffers.push(data))
.on('finish', common.mustCall(() => {
assert.deepStrictEqual(Buffer.concat(pmmResultBuffers), pmmExpected,
'result should match original random garbage');
}));

0 comments on commit 2dd5945

Please sign in to comment.