Skip to content
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 checkPrime crash with large buffers #56559

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

santigimeno
Copy link
Member

Fixes: #56512

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Jan 11, 2025
@@ -176,6 +176,11 @@ Maybe<void> CheckPrimeTraits::AdditionalConfig(
ArrayBufferOrViewContents<unsigned char> candidate(args[offset]);

params->candidate = BignumPointer(candidate.data(), candidate.size());
if (params->candidate.get() == nullptr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simplified bool check should work here

Suggested change
if (params->candidate.get() == nullptr) {
if (!params->candidate) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hadn't noticed the bool operator was implemented. Thanks!

Copy link

codecov bot commented Jan 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.16%. Comparing base (3946f16) to head (9deab1f).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #56559   +/-   ##
=======================================
  Coverage   89.16%   89.16%           
=======================================
  Files         662      662           
  Lines      191751   191756    +5     
  Branches    36900    36906    +6     
=======================================
+ Hits       170972   170981    +9     
+ Misses      13635    13633    -2     
+ Partials     7144     7142    -2     
Files with missing lines Coverage Δ
src/crypto/crypto_random.cc 75.22% <100.00%> (+1.19%) ⬆️

... and 41 files with indirect coverage changes

@@ -254,6 +255,18 @@ for (const checks of [-(2 ** 31), -1, 2 ** 31, 2 ** 32 - 1, 2 ** 32, 2 ** 50]) {
});
}

{
const bytes = randomBytes(67108864);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is generating this large of a random number each time necessary? Should be possible to generate a value statically once that trips this error reliably.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean storing the number into a file in fixtures and use that in the test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't need to be in fixtures (can just be defined inline here) but yes that would work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crypto.checkPrime results in an abort
4 participants