Skip to content

Commit

Permalink
zlib: check if the stream is destroyed before push
Browse files Browse the repository at this point in the history
If the stream is destroyed while the transform is still being
applied, push() should not be called, and the internal state
should be cleared.

See: koajs/compress#60
PR-URL: nodejs#14330
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
mcollina committed Jul 19, 2017
1 parent 030a028 commit aa496f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ function processCallback() {
return;
}

if (self.destroyed) {
this.buffer = null;
return;
}

var availOutAfter = state[0];
var availInAfter = state[1];

Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-zlib-destroy-pipe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const common = require('../common');
const zlib = require('zlib');
const { Writable } = require('stream');

// verify that the zlib transform does not error in case
// it is destroyed with data still in flight

const ts = zlib.createGzip();

const ws = new Writable({
write: common.mustCall((chunk, enc, cb) => {
setImmediate(cb);
ts.destroy();
})
});

const buf = Buffer.allocUnsafe(1024 * 1024 * 20);
ts.end(buf);
ts.pipe(ws);

0 comments on commit aa496f4

Please sign in to comment.