Skip to content

Commit e14e27b

Browse files
mcollinaaduh95
authored andcommitted
zlib: handle params callback after destroy
When params() queues its flush behind another write, destroying the stream invokes the flush callback after the native handle is closed. Propagate the write error instead of accessing the closed handle. Assisted-by: Codex Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: nodejs-private/node-private#1037 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> CVE-ID: CVE-2026-123862
1 parent ae9ab37 commit e14e27b

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

‎lib/zlib.js‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -720,14 +720,16 @@ ObjectSetPrototypeOf(Zlib, ZlibBase);
720720
// before adjusting the parameters. In particular, the call to the native
721721
// `params()` function should not happen while a write is currently in progress
722722
// on the threadpool.
723-
function paramsAfterFlushCallback(level, strategy, callback) {
724-
assert(this._handle, 'zlib binding closed');
725-
this._handle.params(level, strategy);
726-
if (!this.destroyed) {
727-
this._level = level;
728-
this._strategy = strategy;
729-
if (callback) callback();
723+
function paramsAfterFlushCallback(level, strategy, callback, err) {
724+
if (err || this.destroyed || !this._handle) {
725+
if (callback) callback(err);
726+
return;
730727
}
728+
729+
this._handle.params(level, strategy);
730+
this._level = level;
731+
this._strategy = strategy;
732+
if (callback) callback();
731733
}
732734

733735
Zlib.prototype.params = function params(level, strategy, callback) {

‎test/parallel/test-zlib-params.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const zlib = require('zlib');
55
const fixtures = require('../common/fixtures');
@@ -38,3 +38,13 @@ process.once('exit', function() {
3838
const actual = Buffer.concat(bufs);
3939
assert.deepStrictEqual(actual, expected);
4040
});
41+
42+
{
43+
const deflater = zlib.createDeflate();
44+
deflater.write('x');
45+
deflater.params(9, zlib.constants.Z_DEFAULT_STRATEGY,
46+
common.mustCall((err) => {
47+
assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED');
48+
}));
49+
deflater.destroy();
50+
}

0 commit comments

Comments
 (0)