Skip to content

Commit

Permalink
zlib: refactor to avoid unsafe array iteration
Browse files Browse the repository at this point in the history
PR-URL: #36722
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Pooja D P <Pooja.D.P@ibm.com>
  • Loading branch information
aduh95 authored and targos committed Jun 11, 2021
1 parent cf9556d commit 459fe68
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

const {
ArrayBuffer,
ArrayPrototypeForEach,
ArrayPrototypeMap,
ArrayPrototypePush,
Error,
Expand Down Expand Up @@ -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) {
Expand All @@ -812,7 +813,7 @@ function Brotli(opts, mode) {
'number', opts.params[origKey]);
}
brotliInitParamsArray[key] = value;
}
});
}

const handle = mode === BROTLI_DECODE ?
Expand Down

0 comments on commit 459fe68

Please sign in to comment.