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

Fix filling buffers 4 GiB or larger with OsRng::fill_bytes on Windows #99

Merged
merged 1 commit into from
Feb 24, 2016

Conversation

ollie27
Copy link
Contributor

@ollie27 ollie27 commented Feb 24, 2016

CryptGenRandom takes a DWORD (u32) for the length so it only supports
writing u32::MAX bytes at a time.

Casting the length from a usize caused truncation meaning the whole buffer
was not always filled.

cc rust-lang/rust#31841

io::Error::last_os_error());
// CryptGenRandom takes a DWORD (u32) for the length so it only supports
// writing u32::MAX bytes at a time.
for slice in v.chunks_mut(u32::MAX as usize) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this use <DWORD>::max_value()? That should help avoid the import and also avoid hardcoding u32 == DWORD

CryptGenRandom takes a DWORD (u32) for the length so it only supports
writing u32::MAX bytes at a time.

Casting the length from a usize caused truncation meaning the whole buffer
was not always filled.
@ollie27
Copy link
Contributor Author

ollie27 commented Feb 24, 2016

Fixed that small nit.

Do you want me submit the same patch to rust-lang/rust as that also has the same problem?

alexcrichton added a commit that referenced this pull request Feb 24, 2016
Fix filling buffers 4 GiB or larger with OsRng::fill_bytes on Windows
@alexcrichton alexcrichton merged commit c6a573f into rust-random:master Feb 24, 2016
@alexcrichton
Copy link
Contributor

Thanks!

Yeah you can submit one, although it probably doesn't matter much as we're not taking user-specified buffers anyway

bors added a commit to rust-lang/rust that referenced this pull request Feb 26, 2016
CryptGenRandom takes a DWORD (u32) for the length so it only supports
writing u32::MAX bytes at a time.

Casting the length from a usize caused truncation meaning the whole
buffer was not always filled.

cc #31841

This is the same as rust-random/rand#99. I think it's a good idea to keep the implementations in sync.

r? @alexcrichton
pitdicker pushed a commit to pitdicker/rand that referenced this pull request Apr 4, 2018
Fix filling buffers 4 GiB or larger with OsRng::fill_bytes on Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants