From 86cbe4e5d4d90fe4ffe413612f03599a5d65cc09 Mon Sep 17 00:00:00 2001 From: Roberto Bianchi Date: Tue, 24 Nov 2026 10:41:47 +0100 Subject: [PATCH] lib: use indexed append in ZIP central directory parser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit readCentralDirectory() appends one CentralFileHeader per archive entry with ArrayPrototypePush, which is listed among primordials with known performance issues. Assign by the existing loop index instead. The loop runs once per entry, so its trip count grows with archive size. The change is limited to this loop. Validation and error behavior are unchanged. Assisted-by: Claude Code Signed-off-by: Roberto Bianchi PR-URL: https://github.com/nodejs/node/pull/67456 Reviewed-By: Jordan Harband Reviewed-By: Gürgün Dayıoğlu Reviewed-By: James M Snell Reviewed-By: LiviaMedeiros Reviewed-By: René --- lib/internal/zip/headers.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/zip/headers.js b/lib/internal/zip/headers.js index bf6f7901516..3bcb81f23dd 100644 --- a/lib/internal/zip/headers.js +++ b/lib/internal/zip/headers.js @@ -6,7 +6,6 @@ // which walks the central directory into an array of headers. const { - ArrayPrototypePush, MathMax, Number, } = primordials; @@ -604,7 +603,7 @@ function readCentralDirectory(buffer, count) { if (header.diskNumber !== 0) { throw new ERR_ZIP_UNSUPPORTED_FEATURE('multi-disk archives are not supported'); } - ArrayPrototypePush(result, header); + result[index] = header; pos += header.byteLength; } if (pos !== buffer.length) {