From 251a0ffd80b6698d1c53c37f7870fab7dd402584 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 31 Dec 2020 12:31:24 +0100 Subject: [PATCH] zlib: refactor to avoid unsafe array iteration PR-URL: https://github.com/nodejs/node/pull/36722 Reviewed-By: Rich Trott Reviewed-By: James M Snell Reviewed-By: Pooja D P --- lib/zlib.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/zlib.js b/lib/zlib.js index 1d1426635ca99b..38460c1263aa42 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -23,6 +23,7 @@ const { ArrayBuffer, + ArrayPrototypeForEach, ArrayPrototypeMap, ArrayPrototypePush, Error, @@ -803,8 +804,8 @@ function Brotli(opts, mode) { assert(mode === BROTLI_DECODE || mode === BROTLI_ENCODE); TypedArrayPrototypeFill(brotliInitParamsArray, -1); - if (opts && opts.params) { - for (const origKey of ObjectKeys(opts.params)) { + if (opts?.params) { + ArrayPrototypeForEach(ObjectKeys(opts.params), (origKey) => { const key = +origKey; if (NumberIsNaN(key) || key < 0 || key > kMaxBrotliParam || (brotliInitParamsArray[key] | 0) !== -1) { @@ -817,7 +818,7 @@ function Brotli(opts, mode) { 'number', opts.params[origKey]); } brotliInitParamsArray[key] = value; - } + }); } const handle = mode === BROTLI_DECODE ?