@@ -493,6 +493,41 @@ public void DecodesStringLength_LimitConfigurable()
493
493
Assert . Equal ( string8193 , _handler . DecodedHeaders [ string8193 ] ) ;
494
494
}
495
495
496
+ [ Fact ]
497
+ public void DecodesStringLength_ExceedsLimit_Throws ( )
498
+ {
499
+ HPackDecoder decoder = new HPackDecoder ( DynamicTableInitialMaxSize , MaxHeaderFieldSize + 1 ) ;
500
+ string string8191 = new string ( 'a' , MaxHeaderFieldSize - 1 ) ;
501
+ string string8193 = new string ( 'a' , MaxHeaderFieldSize + 1 ) ;
502
+ string string8194 = new string ( 'a' , MaxHeaderFieldSize + 2 ) ;
503
+
504
+ var bytes = new byte [ 3 ] ;
505
+ var success = IntegerEncoder . Encode ( 8194 , 7 , bytes , out var written ) ;
506
+
507
+ byte [ ] encoded = _literalHeaderFieldWithoutIndexingNewName
508
+ . Concat ( new byte [ ] { 0x7f , 0x80 , 0x3f } ) // 8191 encoded with 7-bit prefix, no Huffman encoding
509
+ . Concat ( Encoding . ASCII . GetBytes ( string8191 ) )
510
+ . Concat ( new byte [ ] { 0x7f , 0x80 , 0x3f } ) // 8191 encoded with 7-bit prefix, no Huffman encoding
511
+ . Concat ( Encoding . ASCII . GetBytes ( string8191 ) )
512
+ . Concat ( _literalHeaderFieldWithoutIndexingNewName )
513
+ . Concat ( new byte [ ] { 0x7f , 0x82 , 0x3f } ) // 8193 encoded with 7-bit prefix, no Huffman encoding
514
+ . Concat ( Encoding . ASCII . GetBytes ( string8193 ) )
515
+ . Concat ( new byte [ ] { 0x7f , 0x82 , 0x3f } ) // 8193 encoded with 7-bit prefix, no Huffman encoding
516
+ . Concat ( Encoding . ASCII . GetBytes ( string8193 ) )
517
+ . Concat ( _literalHeaderFieldWithoutIndexingNewName )
518
+ . Concat ( new byte [ ] { 0x7f , 0x83 , 0x3f } ) // 8194 encoded with 7-bit prefix, no Huffman encoding
519
+ . Concat ( Encoding . ASCII . GetBytes ( string8194 ) )
520
+ . Concat ( new byte [ ] { 0x7f , 0x83 , 0x3f } ) // 8194 encoded with 7-bit prefix, no Huffman encoding
521
+ . Concat ( Encoding . ASCII . GetBytes ( string8194 ) )
522
+ . ToArray ( ) ;
523
+
524
+ var ex = Assert . Throws < HPackDecodingException > ( ( ) => decoder . Decode ( encoded , endHeaders : true , handler : _handler ) ) ;
525
+ Assert . Equal ( SR . Format ( SR . net_http_headers_exceeded_length , MaxHeaderFieldSize + 1 ) , ex . Message ) ;
526
+ Assert . Equal ( string8191 , _handler . DecodedHeaders [ string8191 ] ) ;
527
+ Assert . Equal ( string8193 , _handler . DecodedHeaders [ string8193 ] ) ;
528
+ Assert . False ( _handler . DecodedHeaders . ContainsKey ( string8194 ) ) ;
529
+ }
530
+
496
531
[ Fact ]
497
532
public void DecodesStringLength_IndividualBytes ( )
498
533
{
0 commit comments