summaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorKári Tristan Helgason <kthelgason@gmail.com>2016-02-03 18:29:26 +0000
committerBen Noordhuis <info@bnoordhuis.nl>2016-03-15 16:47:10 +0100
commitf380db237b2a6b73fe52b6929fa842cb62e3fa81 (patch)
tree795fee75dfed0961e09a630815f24ebf74a8ebd7 /test/parallel
parent3b2094152e7be6fa6b1f9d57221a3b033b1bb7d3 (diff)
downloadnode-new-f380db237b2a6b73fe52b6929fa842cb62e3fa81.tar.gz
zlib: add support for concatenated members
According to the spec gzipped archives can contain more than one compressed member. Previously Node's gzip implementation would only unzip the first member and throw away the rest of the compressed data. Issue #4306 is an example of this occurring in daily use. Fixes: https://github.com/nodejs/node/issues/4306 PR-URL: https://github.com/nodejs/node/pull/5120 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r--test/parallel/test-zlib-from-concatenated-gzip.js18
-rw-r--r--test/parallel/test-zlib-from-gzip-with-trailing-garbage.js50
2 files changed, 68 insertions, 0 deletions
diff --git a/test/parallel/test-zlib-from-concatenated-gzip.js b/test/parallel/test-zlib-from-concatenated-gzip.js
new file mode 100644
index 0000000000..9bee905b33
--- /dev/null
+++ b/test/parallel/test-zlib-from-concatenated-gzip.js
@@ -0,0 +1,18 @@
+'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 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');
+}));
diff --git a/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js b/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
new file mode 100644
index 0000000000..e5ec42544a
--- /dev/null
+++ b/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
@@ -0,0 +1,50 @@
+'use strict';
+// test unzipping a gzip file that has trailing garbage
+
+const common = require('../common');
+const assert = require('assert');
+const zlib = require('zlib');
+
+// should ignore trailing null-bytes
+let data = Buffer.concat([
+ zlib.gzipSync('abc'),
+ zlib.gzipSync('def'),
+ Buffer(10).fill(0)
+]);
+
+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');
+}));
+
+// if the trailing garbage happens to look like a gzip header, it should
+// throw an error.
+data = Buffer.concat([
+ zlib.gzipSync('abc'),
+ zlib.gzipSync('def'),
+ Buffer([0x1f, 0x8b, 0xff, 0xff]),
+ Buffer(10).fill(0)
+]);
+
+assert.throws(() => zlib.gunzipSync(data));
+
+zlib.gunzip(data, common.mustCall((err, result) => {
+ assert(err);
+}));
+
+// In this case the trailing junk is too short to be a gzip segment
+// So we ignore it and decompression succeeds.
+data = Buffer.concat([
+ zlib.gzipSync('abc'),
+ zlib.gzipSync('def'),
+ Buffer([0x1f, 0x8b, 0xff, 0xff])
+]);
+
+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');
+}));