-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 size_t/int regression node_crypto #35132
Conversation
Review requested:
|
e3bf388
to
0765645
Compare
@addaleax ... Please take a look, I added changes for
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason not to update this for CipherBase
as well, though? Semantically size_t
should be the right type here
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 <[email protected]>
0765645
to
d6b4b8a
Compare
Ok @addaleax, added a fixup for |
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: void CryptoOp(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. |
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. |
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. |
I think that'd be best. @nodejs/crypto? |
I'll work on that in the crypto refactor I'm doing and will get it backported for 14 and 12 also. Thanks Ben. |
#35093 landed that includes these fixes |
#31406 introduced a regression in
Hash
andHmac
update 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