Skip to content

Commit b13e010

Browse files
committed
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. See: koajs/compress#60
1 parent 649d77b commit b13e010

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/zlib.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ function processCallback() {
472472
return;
473473
}
474474

475+
if (self.destroyed) {
476+
this.buffer = null;
477+
return;
478+
}
479+
475480
var availOutAfter = state[0];
476481
var availInAfter = state[1];
477482

Lines changed: 21 additions & 0 deletions
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)