-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Loop on Win32 to satisfy large random byte requests (as is done on Linux) #62364
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
Loop on Win32 to satisfy large random byte requests (as is done on Linux) #62364
Conversation
@swift-ci please test |
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.
Thanks for fixing this!
fatalError(0, "Fatal error: %zd exceeds ULONG_MAX\n", nbytes); | ||
} | ||
while (nbytes > 0) { | ||
auto actual_nbytes = std::min(nbytes, (__swift_size_t)ULONG_MAX); |
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.
It would be nice to use static_cast
as this is C++.
auto actual_nbytes = std::min(nbytes, (__swift_size_t)ULONG_MAX); | |
auto actual_nbytes = std::min(nbytes, static_cast<__swift_size_t>(ULONG_MAX)); |
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.
@compnerd Can the #warning
on line 64 be removed?
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.
Good question. AFAIK the unit tests for random number generation are not conditionalized by platform, are they?
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.
swift_stdlib_random
is used in validation-test/stdlib/Random.swift, on all platforms AFAIK.
The #warning
was originally an #error
, because swift_stdlib_random
was written without access to a compiler for Windows.
132cd3e
to
9de9205
Compare
@swift-ci please test |
This change resolves a crash on Windows when using
SystemRandomNumberGenerator
and requesting a very large number (>ULONG_MAX
) of random bytes.In practice, it's unlikely anyone will be requesting more than 4GB of random bytes, but we don't abort on other platforms and nothing about the API suggests that a large buffer size is unsupported or disallowed.
I have not written a unit test because it would be impractical to request such a large amount of random data during a test run in CI.
Resolves #62130.