File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -638,6 +638,8 @@ impl<T> HeaderMap<T> {
638
638
639
639
if cap > self . indices . len ( ) {
640
640
let cap = cap. next_power_of_two ( ) ;
641
+ assert ! ( cap < MAX_SIZE , "header map reserve over max capacity" ) ;
642
+ assert ! ( cap != 0 , "header map reserve overflowed" ) ;
641
643
642
644
if self . entries . len ( ) == 0 {
643
645
self . mask = cap - 1 ;
Original file line number Diff line number Diff line change @@ -37,6 +37,22 @@ fn smoke() {
37
37
}
38
38
}
39
39
40
+ #[ test]
41
+ #[ should_panic]
42
+ fn reserve_over_capacity ( ) {
43
+ // See https://github.com/hyperium/http/issues/352
44
+ let mut headers = HeaderMap :: < u32 > :: with_capacity ( 32 ) ;
45
+ headers. reserve ( 50_000 ) ; // over MAX_SIZE
46
+ }
47
+
48
+ #[ test]
49
+ #[ should_panic]
50
+ fn reserve_overflow ( ) {
51
+ // See https://github.com/hyperium/http/issues/352
52
+ let mut headers = HeaderMap :: < u32 > :: with_capacity ( 0 ) ;
53
+ headers. reserve ( std:: usize:: MAX ) ; // next_power_of_two overflows
54
+ }
55
+
40
56
#[ test]
41
57
fn drain ( ) {
42
58
let mut headers = HeaderMap :: new ( ) ;
You can’t perform that action at this time.
0 commit comments