From fa9600147de8046475bedaf296230c7c036bd41c Mon Sep 17 00:00:00 2001 From: Roberto Bianchi Date: Thu, 26 Nov 2026 20:16:04 +0100 Subject: [PATCH] zlib: avoid mutable push in sync output collection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit processChunkSync() and processSyncWithDefaults() collected output chunks with buffers.push(), which looks up Array.prototype.push at call time. Replacing that method from user code changed how synchronous zlib calls such as gunzipSync() collected their output. Use indexed assignments instead. Signed-off-by: Roberto Bianchi PR-URL: https://github.com/nodejs/node/pull/67748 Reviewed-By: René Reviewed-By: Jordan Harband Reviewed-By: Gürgün Dayıoğlu Reviewed-By: James M Snell --- lib/zlib.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/zlib.js b/lib/zlib.js index a2d2c158e5d..2230913d534 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -325,7 +325,7 @@ function processSyncWithDefaults(handle, writeState, chunk, flushFlag, if (nread > kMaxLength) throw new ERR_BUFFER_TOO_LARGE(kMaxLength); if (out !== scratch) { - buffers.push(out.subarray(0, have)); + buffers[buffers.length] = out.subarray(0, have); } else if (availOutAfter === 0) { buffers = [out]; } @@ -599,7 +599,7 @@ function processChunkSync(self, chunk, flushFlag) { if (have > 0) { const out = buffer.slice(offset, offset + have); offset += have; - buffers.push(out); + buffers[buffers.length] = out; nread += out.byteLength; if (nread > self._maxOutputLength) {