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: fix node crashing on invalid options #13098

Closed
wants to merge 6 commits into
base: master
from

Conversation

Projects
None yet
@aqrln
Member

aqrln commented May 18, 2017

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

Fixes: #13082

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

zlib: fix node crashing on invalid options
The main reason behind this commit is fixing the Node process crashing
when zlib rejects the given options.

Besides that issue, which got reported and which is linked to this
commit, it turned out that Node also used to crash when a non-numeric
value was passed as the `windowBits` or the `memLevel` option. This was
fixed somewhat inadvertently; initially it was just a stylistic change
to avoid lines spanning longer than 80 characters that was written in a
manner consistent with surrounding code.

Fixes: #13082
@aqrln

This comment has been minimized.

Show comment
Hide comment
@lpinca

This comment has been minimized.

Show comment
Hide comment
@lpinca

lpinca May 18, 2017

Member

@aqrln did something change with zlib 1.2.11?

zlib.createDeflateRaw({ windowBits: 8 })

worked fine with Node.js 6.10.1.

Member

lpinca commented May 18, 2017

@aqrln did something change with zlib 1.2.11?

zlib.createDeflateRaw({ windowBits: 8 })

worked fine with Node.js 6.10.1.

@aqrln

This comment has been minimized.

Show comment
Hide comment
@aqrln

aqrln May 18, 2017

Member

@lpinca frankly, I don't know. But the docs state that 8 is not a valid value of windowBits for raw deflate and gzip.

Member

aqrln commented May 18, 2017

@lpinca frankly, I don't know. But the docs state that 8 is not a valid value of windowBits for raw deflate and gzip.

@lpinca

This comment has been minimized.

Show comment
Hide comment
@lpinca

lpinca May 18, 2017

Member

I wonder if it makes sense to use this remedy

The remedy is to not use 8 with deflateInit2() with this initialization, or at least in that case use 9 with inflateInit2().

in order to avoid the breaking change.

Member

lpinca commented May 18, 2017

I wonder if it makes sense to use this remedy

The remedy is to not use 8 with deflateInit2() with this initialization, or at least in that case use 9 with inflateInit2().

in order to avoid the breaking change.

Show outdated Hide outdated src/node_zlib.cc
Show outdated Hide outdated lib/zlib.js
Show outdated Hide outdated src/node_zlib.cc
@aqrln

This comment has been minimized.

Show comment
Hide comment
@aqrln

aqrln May 18, 2017

Member

@lpinca do you suggest making windowBits 9 when 8 is passed?

Member

aqrln commented May 18, 2017

@lpinca do you suggest making windowBits 9 when 8 is passed?

@lpinca

This comment has been minimized.

Show comment
Hide comment
@lpinca

lpinca May 18, 2017

Member

@aqrln yes use 15 (default value) when 8 is passed, not sure if it is a good idea though. Maybe it is better to do this in userland code.

Member

lpinca commented May 18, 2017

@aqrln yes use 15 (default value) when 8 is passed, not sure if it is a good idea though. Maybe it is better to do this in userland code.

squash! follow an alternative approach
Throw an Error synchronously instead of fiddling with 'error' events.
@aqrln

This comment has been minimized.

Show comment
Hide comment
@aqrln

aqrln May 18, 2017

Member

@addaleax throwing an error synchronously indeed makes it a lot more elegant, thanks.

@lpinca I'm not sure about that too. I'd just document this limitation and not change user's options silently, but let's see what others think about it.

Member

aqrln commented May 18, 2017

@addaleax throwing an error synchronously indeed makes it a lot more elegant, thanks.

@lpinca I'm not sure about that too. I'd just document this limitation and not change user's options silently, but let's see what others think about it.

@aqrln

This comment has been minimized.

Show comment
Hide comment
@cjihrig

LGTM with a couple comments.

Show outdated Hide outdated doc/api/zlib.md
Show outdated Hide outdated lib/zlib.js
Show outdated Hide outdated test/parallel/test-zlib-failed-init.js
@lpinca

This comment has been minimized.

Show comment
Hide comment
@lpinca

lpinca May 18, 2017

Member

Does is makes sense to throw early if opts.windowBits === 8? We already have a check here.

Member

lpinca commented May 18, 2017

Does is makes sense to throw early if opts.windowBits === 8? We already have a check here.

@addaleax

This comment has been minimized.

Show comment
Hide comment
@addaleax

addaleax May 18, 2017

Member

@lpinca I think it would. Are you thinking of doing that instead of this PR, or in addition to? I think the changes here are still good independently

Member

addaleax commented May 18, 2017

@lpinca I think it would. Are you thinking of doing that instead of this PR, or in addition to? I think the changes here are still good independently

@aqrln

This comment has been minimized.

Show comment
Hide comment
@aqrln

aqrln May 18, 2017

Member

@lpinca idk ¯\_(ツ)_/¯ Theoretically, it may change in the future:

For the current implementation of deflate(), a windowBits value of 8 (a window size of 256 bytes) is not supported.

Member

aqrln commented May 18, 2017

@lpinca idk ¯\_(ツ)_/¯ Theoretically, it may change in the future:

For the current implementation of deflate(), a windowBits value of 8 (a window size of 256 bytes) is not supported.

@lpinca

This comment has been minimized.

Show comment
Hide comment
@lpinca

lpinca May 18, 2017

Member

I would make it in addition of these changes to make the error message consistent, but then the "Init error" would not be easy to test.

Member

lpinca commented May 18, 2017

I would make it in addition of these changes to make the error message consistent, but then the "Init error" would not be easy to test.

@aqrln

This comment has been minimized.

Show comment
Hide comment
@aqrln

aqrln May 18, 2017

Member

Yeah, we might do that just for the sake of making the error message more sensible. Seems like all the other ways to break deflateInit2() are already covered by the JavaScript checks.

Member

aqrln commented May 18, 2017

Yeah, we might do that just for the sake of making the error message more sensible. Seems like all the other ways to break deflateInit2() are already covered by the JavaScript checks.

@lpinca

This comment has been minimized.

Show comment
Hide comment
@lpinca

lpinca May 18, 2017

Member

Yes and this explains why it didn't crash before zlib 1.2.11.

Member

lpinca commented May 18, 2017

Yes and this explains why it didn't crash before zlib 1.2.11.

@lpinca

lpinca approved these changes May 18, 2017

LGTM with or without the additional check for opts.windowBits === 8.

@aqrln

This comment has been minimized.

Show comment
Hide comment
@aqrln

aqrln May 18, 2017

Member

That's quite easy to do (aqrln@bf63a37), but I am not really sure about it. I actually see the point in doing so, but being able to test that any sort of failure can be caught seems to be more important, so I'm inclined to leave this PR as it is now unless others would prefer to pull either that commit or something similar to it here.

Member

aqrln commented May 18, 2017

That's quite easy to do (aqrln@bf63a37), but I am not really sure about it. I actually see the point in doing so, but being able to test that any sort of failure can be caught seems to be more important, so I'm inclined to leave this PR as it is now unless others would prefer to pull either that commit or something similar to it here.

@aqrln

This comment has been minimized.

Show comment
Hide comment
@aqrln
Member

aqrln commented May 18, 2017

Show outdated Hide outdated lib/zlib.js
@lpinca

This comment has been minimized.

Show comment
Hide comment
@lpinca

lpinca May 18, 2017

Member

so I'm inclined to leave this PR as it is now unless others would prefer to pull either that commit or something similar to it here.

I agree. As you said this may change again and 8 could be restored as valid value so it's probably better to keep this as is.

Member

lpinca commented May 18, 2017

so I'm inclined to leave this PR as it is now unless others would prefer to pull either that commit or something similar to it here.

I agree. As you said this may change again and 8 could be restored as valid value so it's probably better to keep this as is.

@aqrln

This comment has been minimized.

Show comment
Hide comment
@aqrln
Member

aqrln commented May 19, 2017

jasnell added a commit that referenced this pull request May 28, 2017

zlib: fix node crashing on invalid options
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.

* Fix bugs in the validation logic:
  - Don't conflate 0 and undefined when checking if a field of an
    options object exists.
  - Treat NaN and Infinity values the same way as values of invalid
    types instead of allowing to actually set zlib options to NaN or
    Infinity.

PR-URL: #13098
Fixes: #13082
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

@jasnell jasnell referenced this pull request May 28, 2017

Closed

8.0.0 Release Proposal #12220

gibfahn added a commit to gibfahn/node that referenced this pull request Jun 17, 2017

zlib: fix node crashing on invalid options
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#13201
Fixes: nodejs#13082
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

gibfahn added a commit that referenced this pull request Jun 20, 2017

zlib: fix node crashing on invalid options
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: #13201
Fixes: #13082
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

MylesBorins added a commit that referenced this pull request Jul 11, 2017

zlib: fix node crashing on invalid options
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: #13201
Fixes: #13082
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

@MylesBorins MylesBorins referenced this pull request Jul 18, 2017

Merged

v6.11.2 proposal #14356

MylesBorins added a commit that referenced this pull request Aug 1, 2017

2017-08-01, Version 6.11.2 'Boron' (LTS)
This LTS release comes with 221 commits. This includes 80 which are
test related, 52 which are doc related, 32 which are build / tool
related and 10 commits which are updates to dependencies.

Notable Changes:

* configure:
  - add mips64el to valid_arch (Aditya Anand)
    - #13620
* crypto:
  - Updated root certificates based on [NSS 3.30] (Ben Noordhuis)
    - #13279
    - #12402
    - https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/NSS_3.30_release_notes
* deps:
  - upgrade OpenSSL to version 1.0.2.l (Shigeki Ohtsu)
    - #12913
* http:
  - parse errors are now reported when NODE_DEBUG=http (Sam Roberts)
    - #13206
  - Agent construction can now be envoked without `new` (cjihrig)
    - #12927
* zlib:
  - node will now throw an Error when zlib rejects the value of windowBits,
    instead of crashing (Alexey Orlenko)
    - #13098

PR-URL: #14356

MylesBorins added a commit that referenced this pull request Aug 1, 2017

2017-08-01, Version 6.11.2 'Boron' (LTS)
This LTS release comes with 221 commits. This includes 80 which are
test related, 52 which are doc related, 32 which are build / tool
related and 10 commits which are updates to dependencies.

Notable Changes:

* configure:
  - add mips64el to valid_arch (Aditya Anand)
    - #13620
* crypto:
  - Updated root certificates based on [NSS 3.30] (Ben Noordhuis)
    - #13279
    - #12402
    - https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/NSS_3.30_release_notes
* deps:
  - upgrade OpenSSL to version 1.0.2.l (Shigeki Ohtsu)
    - #12913
* http:
  - parse errors are now reported when NODE_DEBUG=http (Sam Roberts)
    - #13206
  - Agent construction can now be envoked without `new` (cjihrig)
    - #12927
* zlib:
  - node will now throw an Error when zlib rejects the value of windowBits,
    instead of crashing (Alexey Orlenko)
    - #13098

PR-URL: #14356

addaleax added a commit to addaleax/node that referenced this pull request Aug 7, 2017

zlib: fix crash when initializing failed
Unset `mode_` when initializing the zlib stream failed, so that
we don’t try to call the zlib end functions (`deflateEnd()` etc.)
when cleaning up in `ZCtx::Close()`.

Fixes: nodejs#14178
Ref: nodejs#13098

addaleax added a commit that referenced this pull request Aug 9, 2017

zlib: fix crash when initializing failed
Unset `mode_` when initializing the zlib stream failed, so that
we don’t try to call the zlib end functions (`deflateEnd()` etc.)
when cleaning up in `ZCtx::Close()`.

Fixes: #14178
Ref: #13098
PR-URL: #14666
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>

addaleax added a commit that referenced this pull request Aug 9, 2017

zlib: fix crash when initializing failed
Unset `mode_` when initializing the zlib stream failed, so that
we don’t try to call the zlib end functions (`deflateEnd()` etc.)
when cleaning up in `ZCtx::Close()`.

Fixes: #14178
Ref: #13098
PR-URL: #14666
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>

MylesBorins added a commit that referenced this pull request Aug 12, 2017

zlib: fix crash when initializing failed
Unset `mode_` when initializing the zlib stream failed, so that
we don’t try to call the zlib end functions (`deflateEnd()` etc.)
when cleaning up in `ZCtx::Close()`.

Fixes: #14178
Ref: #13098
PR-URL: #14666
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>

MylesBorins added a commit that referenced this pull request Aug 12, 2017

zlib: fix crash when initializing failed
Unset `mode_` when initializing the zlib stream failed, so that
we don’t try to call the zlib end functions (`deflateEnd()` etc.)
when cleaning up in `ZCtx::Close()`.

Fixes: #14178
Ref: #13098
PR-URL: #14666
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>

icarter09 added a commit to icarter09/node that referenced this pull request Aug 12, 2017

zlib: fix crash when initializing failed
Unset `mode_` when initializing the zlib stream failed, so that
we don’t try to call the zlib end functions (`deflateEnd()` etc.)
when cleaning up in `ZCtx::Close()`.

Fixes: nodejs#14178
Ref: nodejs#13098
PR-URL: nodejs#14666
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>

aqrln added a commit to aqrln/node that referenced this pull request Aug 16, 2017

zlib: fix node crashing on invalid options
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
Fixes: nodejs#13082
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

aqrln added a commit to aqrln/node that referenced this pull request Aug 16, 2017

zlib: fix crash when initializing failed
Unset `mode_` when initializing the zlib stream failed, so that
we don’t try to call the zlib end functions (`deflateEnd()` etc.)
when cleaning up in `ZCtx::Close()`.

Fixes: nodejs#14178
Ref: nodejs#13098
PR-URL: nodejs#14666
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>

@aqrln aqrln referenced this pull request Aug 16, 2017

Closed

(v4.x-backport) zlib: fix crash when initializing failed #14860

2 of 2 tasks complete

MylesBorins added a commit that referenced this pull request Sep 19, 2017

zlib: fix node crashing on invalid options
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.

Backport-PR-URL: #14860
PR-URL: #13098
Fixes: #13082
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

MylesBorins added a commit that referenced this pull request Sep 19, 2017

zlib: fix crash when initializing failed
Unset `mode_` when initializing the zlib stream failed, so that
we don’t try to call the zlib end functions (`deflateEnd()` etc.)
when cleaning up in `ZCtx::Close()`.

Fixes: #14178
Ref: #13098
Backport-PR-URL: #14860
PR-URL: #14666
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>

@MylesBorins MylesBorins referenced this pull request Sep 20, 2017

Closed

v4.8.5 proposal #15507

MylesBorins added a commit that referenced this pull request Oct 25, 2017

zlib: fix node crashing on invalid options
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.

Backport-PR-URL: #14860
PR-URL: #13098
Fixes: #13082
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

MylesBorins added a commit that referenced this pull request Oct 25, 2017

zlib: fix crash when initializing failed
Unset `mode_` when initializing the zlib stream failed, so that
we don’t try to call the zlib end functions (`deflateEnd()` etc.)
when cleaning up in `ZCtx::Close()`.

Fixes: #14178
Ref: #13098
Backport-PR-URL: #14860
PR-URL: #14666
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>

@MylesBorins MylesBorins referenced this pull request Oct 25, 2017

Merged

v4.8.6 proposal #16500

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