mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 16:46:56 +00:00

Only treat the gzip magic bytes, when encountered within the file after reading a single block, as the start of a new member when the previous member has ended. 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. Fixes: https://github.com/nodejs/node/issues/5852 PR-URL: https://github.com/nodejs/node/pull/5863 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
'use strict';
|
|
// Test unzipping a gzip file that contains multiple concatenated "members"
|
|
|
|
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'),
|
|
zlib.gzipSync('def')
|
|
]);
|
|
|
|
assert.equal(zlib.gunzipSync(data).toString(), 'abcdef');
|
|
|
|
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');
|
|
}));
|