mirror of
https://github.com/openharmony/third_party_rust_http.git
synced 2026-07-18 20:54:29 -04:00
fix capacity overflows in HeaderMap::reserve
This commit is contained in:
@@ -638,6 +638,8 @@ impl<T> HeaderMap<T> {
|
||||
|
||||
if cap > self.indices.len() {
|
||||
let cap = cap.next_power_of_two();
|
||||
assert!(cap < MAX_SIZE, "header map reserve over max capacity");
|
||||
assert!(cap != 0, "header map reserve overflowed");
|
||||
|
||||
if self.entries.len() == 0 {
|
||||
self.mask = cap - 1;
|
||||
|
||||
@@ -37,6 +37,22 @@ fn smoke() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn reserve_over_capacity() {
|
||||
// See https://github.com/hyperium/http/issues/352
|
||||
let mut headers = HeaderMap::<u32>::with_capacity(32);
|
||||
headers.reserve(50_000); // over MAX_SIZE
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn reserve_overflow() {
|
||||
// See https://github.com/hyperium/http/issues/352
|
||||
let mut headers = HeaderMap::<u32>::with_capacity(0);
|
||||
headers.reserve(std::usize::MAX); // next_power_of_two overflows
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drain() {
|
||||
let mut headers = HeaderMap::new();
|
||||
|
||||
Reference in New Issue
Block a user