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 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.