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 committed Jan 13, 2021
1 parent 3a44f37 commit 251a0ff
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 251a0ff

Please sign in to comment.