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

crypto: fix ucs2/ucs-2/utf16le/utf-16le encoding check #8301

Closed
wants to merge 1 commit into from

Conversation

atstoyanov
Copy link
Contributor

@atstoyanov atstoyanov commented Aug 27, 2016

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

crypto

Description of change

Normalize the encoding in getDecoder() before using it. Fixes an
AssertionError: "Cannot change encoding" when encoding is "ucs2", "ucs-2"
or "utf-16le"

Fixes: #8236

@nodejs-github-bot nodejs-github-bot added the crypto Issues and PRs related to the crypto subsystem. label Aug 27, 2016
@@ -113,3 +113,27 @@ testCipher2(Buffer.from('0123456789abcdef'));
c.update('update', 'utf-8');
c.final('utf8'); // Should not throw.
}

//#8236 regression tests, 'ucs2', 'usc-2', 'utf-16le', 'utf16le' are identical.
Copy link
Member

Choose a reason for hiding this comment

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

nit: Using the full github URL for issue references is cool because that’s more accessible (even clickable in many cases) and helps distinguish from the https://github.com/nodejs/node-v0.x-archive issue tracker

Copy link
Contributor

Choose a reason for hiding this comment

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

also: s/usc-2/ucs-2/

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, space after // please.

@addaleax
Copy link
Member

If you change the https://github.com/nodejs/node/issues/8236 in your commit message into Fixes: https://github.com/nodejs/node/issues/8236, the issue will automatically be closed once this is landed, which is kind of cool.

This generally looks good to me (LGTM), thanks for doing the work here!

/cc @nodejs/crypto

@addaleax
Copy link
Member

@mscdex
Copy link
Contributor

mscdex commented Aug 27, 2016

Minor nit: first line of the commit message is a tad too long (>50)


var decipher = crypto.createDecipher('aes192', key);
var txt = decipher.update(ciph, 'base64', 'utf16le');
txt += decipher.final('utf16le'); //should not throw
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about spacing after //, here and below.

@jasnell
Copy link
Member

jasnell commented Aug 29, 2016

LGTM with the nits addressed.

@atstoyanov
Copy link
Contributor Author

Do I have to amend anything? Or this is done during the merge process?

@addaleax
Copy link
Member

@atstojanov It would be great it you could amend your PR with the suggestions here – doing so allows everyone who wishes to take a look at PRs to make sure that they are in a state in which they can be merged, and allows CI runs with the changes in the way that they are expected to end up in master.


var decipher = crypto.createDecipher('aes192', key);
var txt = decipher.update(ciph, 'base64', 'utf16le');
txt += decipher.final('utf16le'); // Should not throw
Copy link
Member

Choose a reason for hiding this comment

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

Oh, quick nit... Should wrap these in an assert.doesNotThrow() ... e.g.

assert.doesNotThrow(() => txt += decipher.final('utf16le'));

Normalize the encoding in getDecoder() before using it. Fixes an
AssertionError: "Cannot change encoding" when encoding is "ucs2",
"ucs-2" or "utf-16le"

Fixes: nodejs#8236
@addaleax
Copy link
Member

addaleax commented Sep 2, 2016

@addaleax
Copy link
Member

addaleax commented Sep 4, 2016

Landed in a6f7b13, thanks!

@addaleax addaleax closed this Sep 4, 2016
addaleax pushed a commit that referenced this pull request Sep 4, 2016
Normalize the encoding in getDecoder() before using it. Fixes an
AssertionError: "Cannot change encoding" when encoding is "ucs2",
"ucs-2" or "utf-16le"

Fixes: #8236
PR-URL: #8301
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
@Fishrock123 Fishrock123 mentioned this pull request Sep 6, 2016
@Fishrock123
Copy link
Contributor

Depends on #7207

@addaleax
Copy link
Member

addaleax commented Sep 8, 2016

I’ll do a backport tomorrow then, this should probably land in v6.x at some point (would just be adding the internal/util require again)

@addaleax
Copy link
Member

addaleax commented Sep 9, 2016

I’m removing the dont-land-on-v6.x label here since this will land cleanly after the backport in #8463

Fishrock123 pushed a commit that referenced this pull request Sep 14, 2016
Normalize the encoding in getDecoder() before using it. Fixes an
AssertionError: "Cannot change encoding" when encoding is "ucs2",
"ucs-2" or "utf-16le"

Fixes: #8236
PR-URL: #8301
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

should this be backported to v4.x?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem.
Projects
None yet
8 participants