Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/node_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ class ZCtx : public AsyncWrap {
}
}
while (ctx->strm_.avail_in >= GZIP_MIN_HEADER_SIZE &&
ctx->mode_ == GUNZIP) {
ctx->mode_ == GUNZIP &&
ctx->err_ == Z_STREAM_END) {
// Bytes remain in input buffer. Perhaps this is another compressed
// member in the same archive, or just trailing garbage.
// Check the header to find out.
Expand Down
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');
}));