Skip to content

crypto.pseudoRandomBytes results in a segmentation fault #38090

Closed
@zyscoder

Description

@zyscoder

What steps will reproduce the bug?

Setup a node instance,

» node

and run the following javascript code.

crypto.pseudoRandomBytes(2147483648)

Then a segmentation fault occurs.

How often does it reproduce? Is there a required condition?

This problem can always be triggered following the steps above.
Noticed that 2147483647 would not cause this problem. It seems to result from an integer overflow.

What is the expected behavior?

If any error occurs, an exception or other similar error-reporting stuff should be thrown. There is no reason to abort the whole node process.

What do you see instead?

» node
Welcome to Node.js v14.15.1.
Type ".help" for more information.
> crypto.pseudoRandomBytes(2147483647)
<Buffer b7 d9 2d 27 37 50 a1 4b df f3 a2 ad fa 85 16 8e e6 a2 c4 98 a3 48 9a 65 1f 3a c1 9e d8 c1 6e bb ed ef ed 85 dc ae b7 6f 5c 53 7e 09 fb a9 1d 66 7e d5 ... 2147483597 more bytes>
> crypto.pseudoRandomBytes(2147483648)
[1]    2791292 segmentation fault  node

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.cryptoIssues and PRs related to the crypto subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions