diff options
author | Jeff Vander Stoep <jeffv@google.com> | 2022-12-08 01:00:51 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-12-08 01:00:51 +0000 |
commit | 18848fb0daa917e4100d2823f1b0e693a744da0d (patch) | |
tree | 87eaed6099372fd7931cad63d4540e1b1a440c93 | |
parent | 278637eef08ae5020472297b25be8b169c47448e (diff) | |
parent | fd8342d48237c3fb5288554ff95cdcf1cdaeeab9 (diff) | |
download | base64-18848fb0daa917e4100d2823f1b0e693a744da0d.tar.gz |
Upgrade base64 to 0.13.1 am: 4525b0754a am: 5f86885215 am: fd8342d482
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/base64/+/2328735
Change-Id: I2c4b208ce40a212e8373af153f28fe85bccf83ec
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | Cargo.toml | 26 | ||||
-rw-r--r-- | Cargo.toml.orig | 2 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | RELEASE-NOTES.md | 4 | ||||
-rw-r--r-- | patches/encoder.patch | 13 | ||||
-rw-r--r-- | src/decode.rs | 22 |
6 files changed, 49 insertions, 28 deletions
@@ -3,31 +3,41 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "base64" -version = "0.13.0" -authors = ["Alice Maz <alice@alicemaz.com>", "Marshall Pierce <marshall@mpierce.org>"] +version = "0.13.1" +authors = [ + "Alice Maz <alice@alicemaz.com>", + "Marshall Pierce <marshall@mpierce.org>", +] description = "encodes and decodes base64 as bytes or utf8" documentation = "https://docs.rs/base64" readme = "README.md" -keywords = ["base64", "utf8", "encode", "decode", "no_std"] +keywords = [ + "base64", + "utf8", + "encode", + "decode", + "no_std", +] categories = ["encoding"] license = "MIT/Apache-2.0" repository = "https://github.com/marshallpierce/rust-base64" + [profile.bench] debug = true [[bench]] name = "benchmarks" harness = false + [dev-dependencies.criterion] version = "=0.3.2" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 30e73ee..d3cbf3a 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "base64" -version = "0.13.0" +version = "0.13.1" authors = ["Alice Maz <alice@alicemaz.com>", "Marshall Pierce <marshall@mpierce.org>"] description = "encodes and decodes base64 as bytes or utf8" repository = "https://github.com/marshallpierce/rust-base64" @@ -7,14 +7,14 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/base64/base64-0.13.0.crate" + value: "https://static.crates.io/crates/base64/base64-0.13.1.crate" } - version: "0.13.0" + version: "0.13.1" # Dual-licensed, using the least restrictive per go/thirdpartylicenses#same. license_type: NOTICE last_upgrade_date { - year: 2021 - month: 6 - day: 23 + year: 2022 + month: 12 + day: 6 } } diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 1048c1e..6a2e3ca 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,3 +1,7 @@ +# 0.13.1 + +- More precise decode buffer sizing, avoiding unnecessary allocation in `decode_config`. + # 0.13.0 - Config methods are const diff --git a/patches/encoder.patch b/patches/encoder.patch deleted file mode 100644 index ac1cd73..0000000 --- a/patches/encoder.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/src/write/encoder.rs b/src/write/encoder.rs -index 8a48f43..4bb57eb 100644 ---- a/src/write/encoder.rs -+++ b/src/write/encoder.rs -@@ -223,7 +223,7 @@ impl<W: Write> Write for EncoderWriter<W> { - /// Under non-error circumstances, this returns `Ok` with the value being the number of bytes - /// of `input` consumed. The value may be `0`, which interacts poorly with `write_all`, which - /// interprets `Ok(0)` as an error, despite it being allowed by the contract of `write`. See -- /// https://github.com/rust-lang/rust/issues/56889 for more on that. -+ /// <https://github.com/rust-lang/rust/issues/56889> for more on that. - /// - /// If the previous call to `write` provided more (encoded) data than the delegate writer could - /// accept in a single call to its `write`, the remaining data is buffered. As long as buffered diff --git a/src/decode.rs b/src/decode.rs index 4cc937d..e349240 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -107,7 +107,14 @@ pub fn decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, DecodeError> { ///``` #[cfg(any(feature = "alloc", feature = "std", test))] pub fn decode_config<T: AsRef<[u8]>>(input: T, config: Config) -> Result<Vec<u8>, DecodeError> { - let mut buffer = Vec::<u8>::with_capacity(input.as_ref().len() * 4 / 3); + let decoded_length_estimate = (input + .as_ref() + .len() + .checked_add(3) + .expect("decoded length calculation overflow")) + / 4 + * 3; + let mut buffer = Vec::<u8>::with_capacity(decoded_length_estimate); decode_config_buf(input, config, &mut buffer).map(|_| buffer) } @@ -870,4 +877,17 @@ mod tests { } } } + + #[test] + fn decode_config_estimation_works_for_various_lengths() { + for num_prefix_quads in 0..100 { + for suffix in &["AA", "AAA", "AAAA"] { + let mut prefix = "AAAA".repeat(num_prefix_quads); + prefix.push_str(suffix); + // make sure no overflow (and thus a panic) occurs + let res = decode_config(prefix, STANDARD); + assert!(res.is_ok()); + } + } + } } |