Skip to content

Conversation

@aqrln
Copy link
Contributor

This is a partial backport of semver-patch bits of 9e4660b.

This commit fixes the Node process crashing when constructors of classes
of the zlib module are given invalid options.

  • Throw an Error when the zlib library rejects the value of windowBits,
    instead of crashing with an assertion.

  • Treat windowBits and memLevel options consistently with other ones and
    don't crash when non-numeric values are given.

Refs: #13098

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

zlib

This is a partial backport of semver-patch bits of 9e4660b. This commit fixes the Node process crashing when constructors of classes of the zlib module are given invalid options. * Throw an Error when the zlib library rejects the value of windowBits, instead of crashing with an assertion. * Treat windowBits and memLevel options consistently with other ones and don't crash when non-numeric values are given. Refs: nodejs#13098
@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. v6.x zlib Issues and PRs related to the zlib subsystem. labels May 24, 2017
@aqrlnaqrln changed the title zlib: fix node crashing on invalid options(v6.x backport) zlib: fix node crashing on invalid optionsMay 24, 2017
ctx->init_done_ = true;

if (ctx->err_ != Z_OK){
if (dictionary != nullptr){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, you don't need the conditional, the following two lines of code can run correctly whether dictionary is nullptr or not.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice. Thanks.

Copy link
Contributor

@refackrefack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % small nits

lib/zlib.js Outdated
varmemLevel=exports.Z_DEFAULT_MEMLEVEL;
if(typeofopts.memLevel==='number')memLevel=opts.memLevel;

this._handle.init(windowBits||exports.Z_DEFAULT_WINDOWBITS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your changing this line anyway, IMHO handle the fallback in 383 (opts.windowBits && typeof...)

lib/zlib.js Outdated
this._handle.init(windowBits||exports.Z_DEFAULT_WINDOWBITS,
level,
opts.memLevel||exports.Z_DEFAULT_MEMLEVEL,
memLevel||exports.Z_DEFAULT_MEMLEVEL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


// For raw deflate encoding, requests for 256-byte windows are rejected as
// invalid by zlib.
// (http://zlib.net/manual.html#Advanced)
Copy link
Contributor

@refackrefackMay 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to:
Ref: http://zlib.net/manual.html#Advanced

Dismissed

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a good idea to change this one since that's how it is already committed to master.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

Copy link
Contributor

@refackrefack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Win! 💯
(appreciated all the branch juggling you did for that)

@aqrln
Copy link
ContributorAuthor

@MylesBorins
Copy link
Contributor

This can land once we do the next v6.x release

@gibfahn
Copy link
Member

gibfahn pushed a commit to gibfahn/node that referenced this pull request Jun 17, 2017
This is a partial backport of semver-patch bits of 9e4660b. This commit fixes the Node process crashing when constructors of classes of the zlib module are given invalid options. * Throw an Error when the zlib library rejects the value of windowBits, instead of crashing with an assertion. * Treat windowBits and memLevel options consistently with other ones and don't crash when non-numeric values are given. PR-URL: nodejs#13098 Backport-PR-URL: nodejs#13201Fixes: nodejs#13082 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
@gibfahn
Copy link
Member

Landed in 321c90f

@gibfahngibfahn closed this Jun 17, 2017
@aqrlnaqrln deleted the v6.x-backport-13098 branch June 18, 2017 09:47
gibfahn pushed a commit that referenced this pull request Jun 20, 2017
This is a partial backport of semver-patch bits of 9e4660b. This commit fixes the Node process crashing when constructors of classes of the zlib module are given invalid options. * Throw an Error when the zlib library rejects the value of windowBits, instead of crashing with an assertion. * Treat windowBits and memLevel options consistently with other ones and don't crash when non-numeric values are given. PR-URL: #13098 Backport-PR-URL: #13201Fixes: #13082 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jul 11, 2017
This is a partial backport of semver-patch bits of 9e4660b. This commit fixes the Node process crashing when constructors of classes of the zlib module are given invalid options. * Throw an Error when the zlib library rejects the value of windowBits, instead of crashing with an assertion. * Treat windowBits and memLevel options consistently with other ones and don't crash when non-numeric values are given. PR-URL: #13098 Backport-PR-URL: #13201Fixes: #13082 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
@addaleax
Copy link
Member

This should probably be released together with #14666

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.zlibIssues and PRs related to the zlib subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@aqrln@MylesBorins@gibfahn@addaleax@sam-github@refack@jasnell@lpinca@nodejs-github-bot