Skip to content

Commit 3a03c9e

Browse files
authored
Merge pull request rust-random#1096 from tmandry/patch-1
Fix assertions inside read_{u32,u64}_into
2 parents 6ecbe26 + 2cf5120 commit 3a03c9e

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

rand_core/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.6.2] - 2021-02-12
8+
### Fixed
9+
- Fixed assertions in `le::read_u32_into` and `le::read_u64_into` which could
10+
have allowed buffers not to be fully populated (#1096)
11+
712
## [0.6.1] - 2021-01-03
813
### Fixed
914
- Avoid panic when using `RngCore::seed_from_u64` with a seed which is not a

rand_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand_core"
3-
version = "0.6.1"
3+
version = "0.6.2"
44
authors = ["The Rand Project Developers", "The Rust Project Developers"]
55
license = "MIT OR Apache-2.0"
66
readme = "README.md"

rand_core/src/le.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use core::convert::TryInto;
1616
/// Reads unsigned 32 bit integers from `src` into `dst`.
1717
#[inline]
1818
pub fn read_u32_into(src: &[u8], dst: &mut [u32]) {
19-
assert!(4 * src.len() >= dst.len());
19+
assert!(src.len() >= 4 * dst.len());
2020
for (out, chunk) in dst.iter_mut().zip(src.chunks_exact(4)) {
2121
*out = u32::from_le_bytes(chunk.try_into().unwrap());
2222
}
@@ -25,7 +25,7 @@ pub fn read_u32_into(src: &[u8], dst: &mut [u32]) {
2525
/// Reads unsigned 64 bit integers from `src` into `dst`.
2626
#[inline]
2727
pub fn read_u64_into(src: &[u8], dst: &mut [u64]) {
28-
assert!(8 * src.len() >= dst.len());
28+
assert!(src.len() >= 8 * dst.len());
2929
for (out, chunk) in dst.iter_mut().zip(src.chunks_exact(8)) {
3030
*out = u64::from_le_bytes(chunk.try_into().unwrap());
3131
}

0 commit comments

Comments
 (0)