Uh oh!
There was an error while loading. Please reload this page.
crypto: fix size_t/int regression node_crypto - #35132
Conversation
nodejs-github-bot
commented
Sep 9, 2020
Review requested:
|
nodejs-github-bot
commented
Sep 9, 2020
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
e3bf388 to
0765645Comparejasnell
commented
Sep 9, 2020
@addaleax ... Please take a look, I added changes for
|
nodejs-github-bot
commented
Sep 9, 2020
addaleax
left a comment
There was a problem hiding this comment.
Is there any reason not to update this for CipherBase as well, though? Semantically size_t should be the right type here
Uh oh!
There was an error while loading. Please reload this page.
jasnell
commented
Sep 9, 2020
No, not really a good reason not to. We should add a similar size check tho. |
nodejs#31406 introduced a regression in `Hash`, `Hmac`, `SignBase`, and `PublicKeyCipher` Signed-off-by: James M Snell <jasnell@gmail.com>
0765645 to
d6b4b8aComparejasnell
commented
Sep 9, 2020
Ok @addaleax, added a fixup for |
nodejs-github-bot
commented
Sep 9, 2020
bnoordhuis
commented
Sep 10, 2020
I think it would be better to handle this right after the JS -> C++ transition. OpenSSL by and large uses ints for sizes and that's not something we can change. Concretely, I'd check like this: voidCryptoOp(const FunctionCallbackInfo<Value>& args) {
// ...if (!args[0]->IsInt32()) {
// throw TypeError
}
int32_t size = args[0]->Int32Value(context).FromJust();
if (size < 0) {
// throw TypeErorr or RangeError
}
// now either cast to size_t (because known-good range) or stick with int32_t
}That way, code deeper down can safely assume sizes are in a known-good range. With this PR, the range checking is too much all over the place, making it harder to get it right. |
bnoordhuis
commented
Sep 10, 2020
Forgot to mention: the alternative is to have Node.js transparently break up operations over ranges > INT_MAX into smaller ones but that's error prone, might not always be possible, and probably so exceedingly rare as to not be worth the effort. |
jasnell
commented
Sep 10, 2020
In a separate PR I'm making much more far reaching changes that should make it significantly easier to deal with moving forward. It does not yet centralize the type checking / length checking but that's something that can be done easily. I am perfectly fine with an across-the-board restriction for all crypto operation lengths to be
Yeah, I had considered this also and ruled it out for the same reason. |
bnoordhuis
commented
Sep 12, 2020
I think that'd be best. @nodejs/crypto? |
jasnell
commented
Sep 12, 2020
I'll work on that in the crypto refactor I'm doing and will get it backported for 14 and 12 also. Thanks Ben. |
jasnell
commented
Oct 8, 2020
#35093 landed that includes these fixes |
#31406 introduced a regression in
HashandHmacupdate operations.Haven't looked yet, but it's possible that this also affects other Stream-based crypto operations (e.g. sig, verify, etc)Definitely impacted... adding those to the changeset here./cc @addaleax@bnoordhuis
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes