Skip to content

Commit b9cbc48

Browse files
committed
Prevent infinite frame proecssing.
1 parent 03c1f9b commit b9cbc48

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

QuicNet.Infrastructure/Packets/Packet.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using QuickNet.Utilities;
2+
using QuicNet.Infrastructure.Exceptions;
23
using QuicNet.Infrastructure.Frames;
4+
using QuicNet.Infrastructure.Settings;
35
using System;
46
using System.Collections.Generic;
57
using 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()

QuicNet.Infrastructure/Settings/QuicSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)