Skip to content

Commit 6fce1a3

Browse files
mcollinaFishrock123
authored andcommitted
zlib: check if the stream is destroyed before push
If the stream is destroyed while the transform is still being applied, push() should not be called, and the internal state should be cleared. Refs: koajs/compress#60 PR-URL: nodejs#14330 Backport-PR-URL: nodejs#14396 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Conflicts: lib/zlib.js
1 parent 7c3fed5 commit 6fce1a3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Diff for: lib/zlib.js

+3
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ Zlib.prototype._processChunk = function _processChunk(chunk, flushFlag, cb) {
431431
if (self._hadError)
432432
return;
433433

434+
if (self.destroyed)
435+
return;
436+
434437
var have = availOutBefore - availOutAfter;
435438
assert(have >= 0, 'have should not go down');
436439

Diff for: test/parallel/test-zlib-destroy-pipe.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const zlib = require('zlib');
5+
const { Writable } = require('stream');
6+
7+
// verify that the zlib transform does not error in case
8+
// it is destroyed with data still in flight
9+
10+
const ts = zlib.createGzip();
11+
12+
const ws = new Writable({
13+
write: common.mustCall((chunk, enc, cb) => {
14+
setImmediate(cb);
15+
ts.destroy();
16+
})
17+
});
18+
19+
const buf = Buffer.allocUnsafe(1024 * 1024 * 20);
20+
ts.end(buf);
21+
ts.pipe(ws);

0 commit comments

Comments
 (0)