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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Pooja D P <[email protected]>
  • Loading branch information
aduh95 authored and ruyadorno committed Jan 21, 2021
1 parent 1ef92f6 commit 403b595
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 @@ -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) {
Expand All @@ -817,7 +818,7 @@ function Brotli(opts, mode) {
'number', opts.params[origKey]);
}
brotliInitParamsArray[key] = value;
}
});
}

const handle = mode === BROTLI_DECODE ?
Expand Down

0 comments on commit 403b595

Please sign in to comment.