File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
Expand file tree Collapse file tree 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> {
638638
639639 if cap > self . indices . len ( ) {
640640 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" ) ;
641643
642644 if self . entries . len ( ) == 0 {
643645 self . mask = cap - 1 ;
Original file line number Diff line number Diff line change @@ -37,6 +37,22 @@ fn smoke() {
3737 }
3838}
3939
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+
4056#[ test]
4157fn drain ( ) {
4258 let mut headers = HeaderMap :: new ( ) ;
You can’t perform that action at this time.
0 commit comments