From 459fe6864ee67f71f862ef6ec9bfd7dbf3f515bb 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 4cc45a7c26d8b2..b192bd2e3a8be7 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -23,6 +23,7 @@ const { ArrayBuffer, + ArrayPrototypeForEach, ArrayPrototypeMap, ArrayPrototypePush, Error, @@ -798,8 +799,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) { @@ -812,7 +813,7 @@ function Brotli(opts, mode) { 'number', opts.params[origKey]); } brotliInitParamsArray[key] = value; - } + }); } const handle = mode === BROTLI_DECODE ?