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

[v6.x fix] lib: fix zlib async callback after close #16312

Closed

Conversation

nakedible-p
Copy link

@nakedible-p nakedible-p commented Oct 19, 2017

A minimal change that will fix #15625. There are no test cases for this, as I have not been able to find a way to trigger this without actually running a busy system in production. The fix is also minimal because I have been able to verify in production that this fixes the issue, by using code like stream._hadError = true; stream.close(). The fix is for 6.x only, as the code has been heavily rewritten in 8.x and does not contain this bug anymore.

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

zlib

@nodejs-github-bot nodejs-github-bot added v6.x zlib Issues and PRs related to the zlib subsystem. labels Oct 19, 2017
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM as the change. However we might need to add a unit test, if someone can figure out how.

@MylesBorins
Copy link
Contributor

/cc @nodejs/streams @addaleax (re zlib) @nodejs/lts

@MylesBorins MylesBorins self-assigned this Oct 19, 2017
@MylesBorins
Copy link
Contributor

@@ -594,7 +594,7 @@ Zlib.prototype._processChunk = function(chunk, flushFlag, cb) {
this.callback = null;
}

if (self._hadError)
if (self._hadError || !self._handle)
Copy link
Member

@addaleax addaleax Oct 22, 2017

Choose a reason for hiding this comment

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

I think self._hadError implies !self._handle, so this might just be if (!self._handle)?

Copy link
Author

Choose a reason for hiding this comment

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

If you want it that way, I can change it. However, I prefer it this way because:

  1. This is a backport, so the impetus is on minimal changes rather than best code for future as the code is already obsolete
  2. This makes it explicit (and easier to review) that the change can not cause additional breakage by removing some handling that needs to be explicitly checked that all sites which set _hadError also clear _handle.
  3. In case _hadError behavior is changed due to some other case, relying on _handle might not be guaranteed

But, I don't really know the project well enough to know if my arguments are valid or not. So, either way is fine for me, just let me know if it would be better with just if (!self._handle).

@MylesBorins MylesBorins force-pushed the v6.x-staging branch 2 times, most recently from 9219283 to b0fadbe Compare October 26, 2017 04:22
Move the core logic from `LineParser` should fail handling into the
recoverable error check for the REPL default eval.

Fixes: nodejs#15704
Backport-PR-URL: nodejs#15773
PR-URL: nodejs#6171
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
@MylesBorins
Copy link
Contributor

@nakedible can you please rebase and respond to @addaleax's comment

shigeki and others added 4 commits November 14, 2017 14:09
`crypto.createCipher()` sets the fixed IV derived from password and it
leads to a security risk of nonce reuse when counter mode is used.
A warning is emitted when CTR, GCM or CCM is used in
`crypto.createCipher()` to notify users to avoid nonce reuse.

Backport-PR-URL: nodejs#16583
Fixes: nodejs#13801
PR-URL: nodejs#13821
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
EVP_CIPHER_CTX_FLAG_WRAP_ALLOW flag needs to be set in using wrap mode
ciphers. In `crypto.createCipher()`, AES key wrap mode does not use a
default IV defined in RFC3394 but a generated IV with
`EVP_BytesToKey()` to be consistent API behaviors with other ciphers.

The built-in AES wrap mode in OpenSSL is not supported in FIPS mode as
http://openssl.6102.n7.nabble.com/AES-Key-Wrap-in-FIPS-Mode-td50238.html
so its tests in FIPS mode are skipped.

Backport-PR-URL: nodejs#16584
Fixes: nodejs#15009
PR-URL: nodejs#15037
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
This exception can logically never happen because of the key stretching
that takes place first.  Failure must therefore be a bug in Node.js and
not in the executing script.

Backport-PR-URL: nodejs#16585
PR-URL: nodejs#15183
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Closing a zlib stream may throw an uncaught exception afterwards if
there was a pending callback still to be invoked. This adds a very
minimal fix to the issue as all of this code has been rewritten in later
versions.

Fixes: nodejs#15625
@nakedible-p nakedible-p force-pushed the fix-zlib-close-for-v6.x branch from 7ce4aea to a390a32 Compare November 14, 2017 20:01
@nakedible-p
Copy link
Author

Rebased. Sorry, sort of dropped the ball on this, because I couldn't get tests for v6.x-staging to pass on my machine. Was something to do with a couple network tests not returning ENOTFOUND but some error.

@MylesBorins
Copy link
Contributor

@addaleax is this ready to land now?

@MylesBorins
Copy link
Contributor

ping @addaleax

1 similar comment
@MylesBorins
Copy link
Contributor

ping @addaleax

@addaleax
Copy link
Member

@MylesBorins Yes, this is still ready :)

MylesBorins pushed a commit that referenced this pull request Jan 19, 2018
Closing a zlib stream may throw an uncaught exception afterwards if
there was a pending callback still to be invoked. This adds a very
minimal fix to the issue as all of this code has been rewritten in later
versions.

Fixes: #15625
PR-URL: #16312
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
@MylesBorins
Copy link
Contributor

landed in 5707f83

@MylesBorins MylesBorins mentioned this pull request Jan 24, 2018
MylesBorins pushed a commit that referenced this pull request Feb 11, 2018
Closing a zlib stream may throw an uncaught exception afterwards if
there was a pending callback still to be invoked. This adds a very
minimal fix to the issue as all of this code has been rewritten in later
versions.

Fixes: #15625
PR-URL: #16312
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
@MylesBorins MylesBorins reopened this Feb 12, 2018
@MylesBorins
Copy link
Contributor

MylesBorins commented Feb 12, 2018

This unfortunately broke ws on osx and needed to be backed out of v6.x

We currently have ws marked as flaky on linux and skipping on windows, so this will need to be tested against an OSX box. More than happy to help run the tests if that is an issue.

To reproduce with this branch run

npm i -g citgm
citgm -v verbose ws

edit: test failure was a timeout"

@MylesBorins MylesBorins force-pushed the v6.x-staging branch 3 times, most recently from 5bdb18e to 691cd5a Compare February 13, 2018 00:33
@MylesBorins MylesBorins added the stalled Issues and PRs that are stalled. label Mar 20, 2018
@MylesBorins MylesBorins force-pushed the v6.x-staging branch 2 times, most recently from 0a4c79b to 988cca8 Compare March 30, 2018 03:28
@MylesBorins
Copy link
Contributor

Closing as we never had resolution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stalled Issues and PRs that are stalled. zlib Issues and PRs related to the zlib subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants