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: https://github.com/koajs/compress/issues/60 PR-URL: https://github.com/nodejs/node/pull/14330 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
030a0285d8
commit
aa496f4bee
@ -472,6 +472,11 @@ function processCallback() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.destroyed) {
|
||||
this.buffer = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var availOutAfter = state[0];
|
||||
var availInAfter = state[1];
|
||||
|
||||
|
21
test/parallel/test-zlib-destroy-pipe.js
Normal file
21
test/parallel/test-zlib-destroy-pipe.js
Normal file
@ -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);
|
Loading…
x
Reference in New Issue
Block a user