File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Text ;
5+ using System . Threading . Tasks ;
6+
7+ namespace QuicNet . Infrastructure . Exceptions
8+ {
9+ public class ProtocolException : Exception
10+ {
11+ public ProtocolException ( )
12+ {
13+ }
14+
15+ public ProtocolException ( string message ) : base ( message )
16+ {
17+ }
18+ }
19+ }
Original file line number Diff line number Diff line change 11using QuickNet . Utilities ;
2+ using QuicNet . Infrastructure . Exceptions ;
23using QuicNet . Infrastructure . Frames ;
4+ using QuicNet . Infrastructure . Settings ;
35using System ;
46using System . Collections . Generic ;
57using System . Text ;
@@ -33,14 +35,20 @@ public virtual void DecodeFrames(ByteArray array)
3335 {
3436 FrameParser factory = new FrameParser ( array ) ;
3537 Frame result ;
36- while ( array . HasData ( ) )
38+ int frames = 0 ;
39+ while ( array . HasData ( ) && frames <= QuicSettings . MaximumFramesPerPacket )
3740 {
3841 result = factory . GetFrame ( ) ;
3942 if ( result != null )
4043 _frames . Add ( result ) ;
4144
45+ frames ++ ;
46+
4247 // TODO: Possibily handle broken frames.
4348 }
49+
50+ if ( array . HasData ( ) )
51+ throw new ProtocolException ( "Unexpected number of frames or possibly corrupted frame was sent." ) ;
4452 }
4553
4654 public virtual byte [ ] EncodeFrames ( )
Original file line number Diff line number Diff line change @@ -36,5 +36,10 @@ public class QuicSettings
3636 /// Should the server buffer packets that came before the initial packet?
3737 /// </summary>
3838 public const bool ShouldBufferPacketsBeforeConnection = false ;
39+
40+ /// <summary>
41+ /// Limit the maximum number of frames a packet can carry.
42+ /// </summary>
43+ public const int MaximumFramesPerPacket = 10 ;
3944 }
4045}
You can’t perform that action at this time.
0 commit comments