diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-02-28 22:25:59 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-04 00:13:40 +0100 |
commit | 28db96f31c2724b16d6b9bec19c600023365b7cc (patch) | |
tree | e81006bc403df7ee0cf23b05a73eb0a647db95c2 /test/parallel/test-zlib-premature-end.js | |
parent | a0778a97e19fb6e661a4277f18f758443d20470c (diff) | |
download | android-node-v8-28db96f31c2724b16d6b9bec19c600023365b7cc.tar.gz android-node-v8-28db96f31c2724b16d6b9bec19c600023365b7cc.tar.bz2 android-node-v8-28db96f31c2724b16d6b9bec19c600023365b7cc.zip |
zlib: report premature ends earlier
Report end-of-stream when decompressing when we detect it,
and do not wait until the writable side of a zlib stream
is closed as well.
Refs: https://github.com/nodejs/node/issues/26332
PR-URL: https://github.com/nodejs/node/pull/26363
Refs: https://github.com/nodejs/node/issues/26332
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-zlib-premature-end.js')
-rw-r--r-- | test/parallel/test-zlib-premature-end.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/parallel/test-zlib-premature-end.js b/test/parallel/test-zlib-premature-end.js new file mode 100644 index 0000000000..9e191c4c88 --- /dev/null +++ b/test/parallel/test-zlib-premature-end.js @@ -0,0 +1,33 @@ +'use strict'; +const common = require('../common'); +const zlib = require('zlib'); +const assert = require('assert'); + +const input = '0123456789'.repeat(4); + +for (const [ compress, decompressor ] of [ + [ zlib.deflateRawSync, zlib.createInflateRaw ], + [ zlib.deflateSync, zlib.createInflate ], + [ zlib.brotliCompressSync, zlib.createBrotliDecompress ] +]) { + const compressed = compress(input); + const trailingData = Buffer.from('not valid compressed data'); + + for (const variant of [ + (stream) => { stream.end(compressed); }, + (stream) => { stream.write(compressed); stream.write(trailingData); }, + (stream) => { stream.write(compressed); stream.end(trailingData); }, + (stream) => { stream.write(Buffer.concat([compressed, trailingData])); }, + (stream) => { stream.end(Buffer.concat([compressed, trailingData])); } + ]) { + let output = ''; + const stream = decompressor(); + stream.setEncoding('utf8'); + stream.on('data', (chunk) => output += chunk); + stream.on('end', common.mustCall(() => { + assert.strictEqual(output, input); + assert.strictEqual(stream.bytesWritten, compressed.length); + })); + variant(stream); + } +} |