镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit 6c223db

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 a84a01d commit 6c223db

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
@@ -735,14 +735,16 @@ ObjectSetPrototypeOf(Zlib, ZlibBase);
735735
// before adjusting the parameters. In particular, the call to the native
736736
// `params()` function should not happen while a write is currently in progress
737737
// on the threadpool.
738-
function paramsAfterFlushCallback(level, strategy, callback) {
739-
assert(this._handle, 'zlib binding closed');
740-
this._handle.params(level, strategy);
741-
if (!this.destroyed) {
742-
this._level = level;
743-
this._strategy = strategy;
744-
if (callback) callback();
738+
function paramsAfterFlushCallback(level, strategy, callback, err) {
739+
if (err || this.destroyed || !this._handle) {
740+
if (callback) callback(err);
741+
return;
745742
}
743+
744+
this._handle.params(level, strategy);
745+
this._level = level;
746+
this._strategy = strategy;
747+
if (callback) callback();
746748
}
747749

748750
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)