crypto: fix regression in randomFill/randomBytes#35135
crypto: fix regression in randomFill/randomBytes#35135jasnell wants to merge 4 commits intonodejs:masterfrom
Conversation
Fixes a segfault when a buffer larger than 2**31-1 is passed in to randomFill/randomFillSync or when a size larger than 2**31-1 is passed in to randomBytes. Signed-off-by: James M Snell <jasnell@gmail.com>
|
Review requested:
|
bnoordhuis
left a comment
There was a problem hiding this comment.
Seems fine to me. Requesting more than a few kilobytes of randomness is already questionable (what do you need so much entropy for?), let alone 2 GB.
Co-authored-by: Denys Otrishko <shishugi@gmail.com>
|
|
||
| * `buffer` {Buffer|TypedArray|DataView} Must be supplied. | ||
| * `buffer` {Buffer|TypedArray|DataView} Must be supplied. The | ||
| size of the provided `buffer` must not be larger than `2**31 - 1`. |
There was a problem hiding this comment.
Ditto
| size of the provided `buffer` must not be larger than `2**31 - 1`. | |
| size of the provided `buffer` must be less or equal to `2**31 - 1`. |
There was a problem hiding this comment.
FWIW, I think less than or equal to would be the way to go here and in the other three examples, but I'm not blocking. Whatever wording is used is fine by me. Can always be changed later.
| size of the provided `buffer` must not be larger than `2**31 - 1`. | |
| size of the provided `buffer` must be less than or equal to `2**31 - 1`. |
| * `offset` {number} **Default:** `0` | ||
| * `size` {number} **Default:** `buffer.length - offset` | ||
| * `size` {number} **Default:** `buffer.length - offset`. The `size` | ||
| must not be larger than `2**31 - 1`. |
There was a problem hiding this comment.
| must not be larger than `2**31 - 1`. | |
| must be less or equal to `2**31 - 1`. |
|
|
||
| * `buffer` {Buffer|TypedArray|DataView} Must be supplied. | ||
| * `buffer` {Buffer|TypedArray|DataView} Must be supplied. The size | ||
| of the provided `buffer` must not be larger than `2**31 - 1`. |
There was a problem hiding this comment.
| of the provided `buffer` must not be larger than `2**31 - 1`. | |
| of the provided `buffer` must be less or equal to `2**31 - 1`. |
| * `offset` {number} **Default:** `0` | ||
| * `size` {number} **Default:** `buffer.length - offset` | ||
| * `size` {number} **Default:** `buffer.length - offset`. The `size` | ||
| must not be larger than `2**31 - 1`. |
There was a problem hiding this comment.
| must not be larger than `2**31 - 1`. | |
| must be less or equal to `2**31 - 1`. |
| CHECK_LE(offset + size, Buffer::Length(args[0])); // Bounds check. | ||
| Environment* env = Environment::GetCurrent(args); | ||
|
|
||
| if (size > INT_MAX) |
There was a problem hiding this comment.
Isn't it better to do proper validation in JS and only use CHECK_LE here?
|
#35093 landed that incorporated most of these changes. |
Fixes a segfault when a buffer larger than
2**31-1is passed in to randomFill/randomFillSync or when a size larger than2**31-1is passed in to randomBytes.I opened this one separate because we should decide if this is the way we want to handle this. This PR adds a throw if the size is larger than
2**31-1. Alternatively, we could allow larger values by splitting it into multiple calls toRAND_bytes. That said, I'd like to believe that asking for random values larger than2**31-1is going to be exceedingly rare (I'd really hope), so I think the throw is sufficient here.Related to: #35132
Signed-off-by: James M Snell jasnell@gmail.com
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes