zlib: avoid mutable push in sync output collection

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 <roberto.bianchi@spendesk.com>
PR-URL: https://github.com/nodejs/node/pull/67748
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Roberto Bianchi authored and GitHub committed 2026-11-26 19:16:04 +00:00
1 parent 2dd55c3d47
commit fa9600147d
1 file changed
+2 -2
+2 -2
View File
@@ -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) {