Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zlib: refactor to avoid unsafe array iteration #36722

Merged
merged 1 commit into from Jan 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/zlib.js
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) => {
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
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