crypto: coerce -0 keylen to +0 in pbkdf2 and scrypt#63531
Open
ljharb wants to merge 2 commits into
Open
Conversation
`validateInt32(keylen, 'keylen', 0)` lets `-0` through: `typeof -0` is
`'number'`, `Number.isInteger(-0)` is `true`, and `-0 < 0` is `false`.
The value then reaches the PBKDF2Job binding, whose `IsInt32()` check
fails (V8 boxes `-0` as a HeapNumber rather than a tagged SMI) and
aborts the process with SIGABRT.
Coerce `keylen` to `+0`
after validation so the binding sees a true Int32.
Reachable from any caller that forwards a JSON-parsed value,
since `JSON.parse('{"keylen":-0}').keylen` preserves the sign.
Signed-off-by: Jordan Harband <ljharb@gmail.com>
Collaborator
|
Review requested:
|
e4b488e to
9700ffe
Compare
Member
|
@ljharb can you throw in a fix for scrypt too? |
Member
|
Outside of pbkdf2 and scrypt there are also instances in cipher, diffiehellman, keygen, hash, random. I can tackle those separately in a followup if you want, or you can, up to you. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #63531 +/- ##
==========================================
- Coverage 90.32% 90.31% -0.02%
==========================================
Files 730 730
Lines 234152 234156 +4
Branches 43900 43912 +12
==========================================
- Hits 211499 211467 -32
- Misses 14374 14418 +44
+ Partials 8279 8271 -8
🚀 New features to boost your workflow:
|
This comment was marked as outdated.
This comment was marked as outdated.
Mirror of the prior pbkdf2 fix. `validateInt32(keylen, 'keylen', 0)` lets `-0` through (since `-0 < 0` is `false`), and the ScryptJob binding's `IsInt32()` check at `crypto_scrypt.cc` aborts the process with SIGABRT because V8 boxes `-0` as a HeapNumber rather than a tagged SMI. Coerce `keylen` to `+0` after validation.
6a406f2 to
c095afb
Compare
panva
approved these changes
May 24, 2026
This comment was marked as outdated.
This comment was marked as outdated.
jasnell
approved these changes
May 24, 2026
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
lpinca
approved these changes
May 24, 2026
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
validateInt32(keylen, 'keylen', 0)lets-0through:typeof -0is'number',Number.isInteger(-0)istrue, and-0 < 0isfalse.The value then reaches the PBKDF2Job binding, whose
IsInt32()check fails (V8 boxes-0as a HeapNumber rather than a tagged SMI) and aborts the process with SIGABRT.Coerce
keylento+0after validation so the binding sees a true Int32.Reachable from any caller that forwards a JSON-parsed value, since
JSON.parse('{"keylen":-0}').keylenpreserves the sign.(an alternative implementation would be to throw on
-0- this seemed friendlier, but I'm happy to do that instead, if folks prefer)