Skip to content

Commit 7fa4339

Browse files
Merge pull request marshallpierce#196 from marshallpierce/mp/port-decode-size
Merge 0.13.1
2 parents a675443 + caadeaa commit 7fa4339

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ workflows:
1414
# be easier on the CI hosts since presumably those fat lower layers will already be cached, and
1515
# therefore faster than a minimal, customized alpine.
1616
# MSRV
17-
'rust:1.47.0'
17+
'rust:1.51.0'
1818
]
1919
# a hacky scheme to work around CircleCI's inability to deal with mutable docker tags, forcing us to
2020
# get a nightly or stable toolchain via rustup instead of a mutable docker tag

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords = ["base64", "utf8", "encode", "decode", "no_std"]
1010
categories = ["encoding"]
1111
license = "MIT OR Apache-2.0"
1212
edition = "2018"
13-
rust-version = "1.47.0"
13+
rust-version = "1.51.0"
1414

1515
[[bench]]
1616
name = "benchmarks"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ If you have a `Read` (e.g. reading a file or network socket), there are various
4545

4646
## Rust version compatibility
4747

48-
The minimum required Rust version is 1.47.0.
48+
The minimum required Rust version is 1.51.0.
4949

5050
# Contributing
5151

RELEASE-NOTES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 0.20.0
22

3+
## Next
4+
5+
- MSRV is now 1.51.0 to keep up with `criterion`
6+
37
## 0.20.0-alpha.1
48

59
### Breaking changes
@@ -13,6 +17,10 @@
1317
- `DecoderReader` now owns its inner reader, and can expose it via `into_inner()`. For symmetry, `EncoderWriter` can do the same with its writer.
1418
- `encoded_len` is now public so you can size encode buffers precisely.
1519

20+
# 0.13.1
21+
22+
- More precise decode buffer sizing, avoiding unnecessary allocation in `decode_config`.
23+
1624
# 0.13.0
1725

1826
- Config methods are const

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv = "1.47.0"
1+
msrv = "1.51.0"

src/decode.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,14 @@ pub fn decode_engine<E: Engine, T: AsRef<[u8]>>(
9595
input: T,
9696
engine: &E,
9797
) -> Result<Vec<u8>, DecodeError> {
98-
let mut buffer = Vec::<u8>::new();
98+
let decoded_length_estimate = (input
99+
.as_ref()
100+
.len()
101+
.checked_add(3)
102+
.expect("decoded length calculation overflow"))
103+
/ 4
104+
* 3;
105+
let mut buffer = Vec::<u8>::with_capacity(decoded_length_estimate);
99106
decode_engine_vec(input, &mut buffer, engine).map(|_| buffer)
100107
}
101108

@@ -340,4 +347,17 @@ mod tests {
340347
assert_eq!(orig_data, decode_buf);
341348
}
342349
}
350+
351+
#[test]
352+
fn decode_engine_estimation_works_for_various_lengths() {
353+
for num_prefix_quads in 0..100 {
354+
for suffix in &["AA", "AAA", "AAAA"] {
355+
let mut prefix = "AAAA".repeat(num_prefix_quads);
356+
prefix.push_str(suffix);
357+
// make sure no overflow (and thus a panic) occurs
358+
let res = decode_engine(prefix, &DEFAULT_ENGINE);
359+
assert!(res.is_ok());
360+
}
361+
}
362+
}
343363
}

0 commit comments

Comments
 (0)