aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2021-02-19 17:20:30 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-02-19 17:20:30 +0000
commitfd82a8843e6ca745eddc7036f31bbb653ae0271c (patch)
tree6be8269cdfd8fe766424806fd5f9415196a8a1df
parent26e78d3a1f8388a99e7666598ce670571076223e (diff)
parent938d22c30823dda9fa8680354d25afcdbfbd622d (diff)
downloadrand_core-fd82a8843e6ca745eddc7036f31bbb653ae0271c.tar.gz
Upgrade rust/crates/rand_core to 0.6.2 am: cf398cf7b4 am: 87a47c637f am: 938d22c308
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/rand_core/+/1592901 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I052e9c4559959e7ecfaaefa7df8db4ba6f9263b8
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp46
-rw-r--r--CHANGELOG.md12
-rw-r--r--Cargo.toml9
-rw-r--r--Cargo.toml.orig9
-rw-r--r--METADATA10
-rw-r--r--TEST_MAPPING11
-rw-r--r--src/le.rs4
-rw-r--r--src/lib.rs22
9 files changed, 64 insertions, 61 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 0db4f9b..3fd44e0 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
{
"git": {
- "sha1": "98e220c30234370fb04ba928799ebd9727fc049a"
+ "sha1": "3a03c9eb5350e03a3f540dba2ee34e0984f2c2c2"
}
}
diff --git a/Android.bp b/Android.bp
index 129006d..b0e0717 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,42 +1,5 @@
// This file is generated by cargo2android.py --device --run --features=std --dependencies --tests.
-package {
- default_applicable_licenses: ["external_rust_crates_rand_core_license"],
-}
-
-// Added automatically by a large-scale-change that took the approach of
-// 'apply every license found to every target'. While this makes sure we respect
-// every license restriction, it may not be entirely correct.
-//
-// e.g. GPL in an MIT project might only apply to the contrib/ directory.
-//
-// Please consider splitting the single license below into multiple licenses,
-// taking care not to lose any license_kind information, and overriding the
-// default license using the 'licenses: [...]' property on targets as needed.
-//
-// For unused files, consider creating a 'filegroup' with "//visibility:private"
-// to attach the license to, and including a comment whether the files may be
-// used in the current project.
-//
-// large-scale-change included anything that looked like it might be a license
-// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc.
-//
-// Please consider removing redundant or irrelevant files from 'license_text:'.
-// http://go/android-license-faq
-license {
- name: "external_rust_crates_rand_core_license",
- visibility: [":__subpackages__"],
- license_kinds: [
- "SPDX-license-identifier-Apache-2.0",
- "SPDX-license-identifier-MIT",
- ],
- license_text: [
- "COPYRIGHT",
- "LICENSE-APACHE",
- "LICENSE-MIT",
- ],
-}
-
rust_library {
name: "librand_core",
host_supported: true,
@@ -73,6 +36,9 @@ rust_defaults {
rust_test_host {
name: "rand_core_host_test_src_lib",
defaults: ["rand_core_defaults"],
+ test_options: {
+ unit_test: true,
+ },
}
rust_test {
@@ -81,6 +47,6 @@ rust_test {
}
// dependent_library ["feature_list"]
-// cfg-if-0.1.10
-// getrandom-0.2.0 "std"
-// libc-0.2.81
+// cfg-if-1.0.0
+// getrandom-0.2.2 "std"
+// libc-0.2.86
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 63a8bb8..23d1fa5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [0.6.2] - 2021-02-12
+### Fixed
+- Fixed assertions in `le::read_u32_into` and `le::read_u64_into` which could
+ have allowed buffers not to be fully populated (#1096)
+
+## [0.6.1] - 2021-01-03
+### Fixed
+- Avoid panic when using `RngCore::seed_from_u64` with a seed which is not a
+ multiple of four (#1082)
+### Other
+- Enable all stable features in the playground (#1081)
+
## [0.6.0] - 2020-12-08
### Breaking changes
- Bump MSRV to 1.36, various code improvements (#1011)
diff --git a/Cargo.toml b/Cargo.toml
index 508f993..51b8385 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,11 +13,11 @@
[package]
edition = "2018"
name = "rand_core"
-version = "0.6.0"
+version = "0.6.2"
authors = ["The Rand Project Developers", "The Rust Project Developers"]
description = "Core random number generator traits and tools for implementation.\n"
-homepage = "https://crates.io/crates/rand_core"
-documentation = "https://rust-random.github.io/rand/rand_core/"
+homepage = "https://rust-random.github.io/book"
+documentation = "https://docs.rs/rand_core"
readme = "README.md"
keywords = ["random", "rng"]
categories = ["algorithms", "no-std"]
@@ -26,6 +26,9 @@ repository = "https://github.com/rust-random/rand"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "doc_cfg"]
+
+[package.metadata.playground]
+all-features = true
[dependencies.getrandom]
version = "0.2"
optional = true
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index c383b31..d460757 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,12 +1,12 @@
[package]
name = "rand_core"
-version = "0.6.0"
+version = "0.6.2"
authors = ["The Rand Project Developers", "The Rust Project Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/rust-random/rand"
-documentation = "https://rust-random.github.io/rand/rand_core/"
-homepage = "https://crates.io/crates/rand_core"
+documentation = "https://docs.rs/rand_core"
+homepage = "https://rust-random.github.io/book"
description = """
Core random number generator traits and tools for implementation.
"""
@@ -28,3 +28,6 @@ getrandom = { version = "0.2", optional = true }
# RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --no-deps --open
all-features = true
rustdoc-args = ["--cfg", "doc_cfg"]
+
+[package.metadata.playground]
+all-features = true
diff --git a/METADATA b/METADATA
index 37999a5..0e7aa20 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/rand_core/rand_core-0.6.0.crate"
+ value: "https://static.crates.io/crates/rand_core/rand_core-0.6.2.crate"
}
- version: "0.6.0"
+ version: "0.6.2"
license_type: NOTICE
last_upgrade_date {
- year: 2020
- month: 12
- day: 15
+ year: 2021
+ month: 2
+ day: 17
}
}
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 7b95466..963506b 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -1,7 +1,16 @@
-// Generated by cargo2android.py for tests in Android.bp
+// Generated by update_crate_tests.py for tests that depend on this crate.
{
"presubmit": [
{
+ "name": "rand_xorshift_device_test_tests_mod"
+ },
+ {
+ "name": "keystore2_test"
+ },
+ {
+ "name": "rand_xorshift_device_test_src_lib"
+ },
+ {
"name": "rand_core_device_test_src_lib"
}
]
diff --git a/src/le.rs b/src/le.rs
index fa33892..ed42e57 100644
--- a/src/le.rs
+++ b/src/le.rs
@@ -16,7 +16,7 @@ use core::convert::TryInto;
/// Reads unsigned 32 bit integers from `src` into `dst`.
#[inline]
pub fn read_u32_into(src: &[u8], dst: &mut [u32]) {
- assert!(4 * src.len() >= dst.len());
+ assert!(src.len() >= 4 * dst.len());
for (out, chunk) in dst.iter_mut().zip(src.chunks_exact(4)) {
*out = u32::from_le_bytes(chunk.try_into().unwrap());
}
@@ -25,7 +25,7 @@ pub fn read_u32_into(src: &[u8], dst: &mut [u32]) {
/// Reads unsigned 64 bit integers from `src` into `dst`.
#[inline]
pub fn read_u64_into(src: &[u8], dst: &mut [u64]) {
- assert!(8 * src.len() >= dst.len());
+ assert!(src.len() >= 8 * dst.len());
for (out, chunk) in dst.iter_mut().zip(src.chunks_exact(8)) {
*out = u64::from_le_bytes(chunk.try_into().unwrap());
}
diff --git a/src/lib.rs b/src/lib.rs
index ff553a3..7e847ae 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -300,20 +300,30 @@ pub trait SeedableRng: Sized {
/// considered a value-breaking change.
fn seed_from_u64(mut state: u64) -> Self {
// We use PCG32 to generate a u32 sequence, and copy to the seed
- const MUL: u64 = 6364136223846793005;
- const INC: u64 = 11634580027462260723;
+ fn pcg32(state: &mut u64) -> [u8; 4] {
+ const MUL: u64 = 6364136223846793005;
+ const INC: u64 = 11634580027462260723;
- let mut seed = Self::Seed::default();
- for chunk in seed.as_mut().chunks_mut(4) {
// We advance the state first (to get away from the input value,
// in case it has low Hamming Weight).
- state = state.wrapping_mul(MUL).wrapping_add(INC);
+ *state = state.wrapping_mul(MUL).wrapping_add(INC);
+ let state = *state;
// Use PCG output function with to_le to generate x:
let xorshifted = (((state >> 18) ^ state) >> 27) as u32;
let rot = (state >> 59) as u32;
let x = xorshifted.rotate_right(rot);
- chunk.copy_from_slice(&x.to_le_bytes());
+ x.to_le_bytes()
+ }
+
+ let mut seed = Self::Seed::default();
+ let mut iter = seed.as_mut().chunks_exact_mut(4);
+ for chunk in &mut iter {
+ chunk.copy_from_slice(&pcg32(&mut state));
+ }
+ let rem = iter.into_remainder();
+ if !rem.is_empty() {
+ rem.copy_from_slice(&pcg32(&mut state)[..rem.len()]);
}
Self::from_seed(seed)