@@ -29,6 +29,13 @@ internal static BitStream UnwrapMessage(BitStream inputStream, uint clientId, ou
29
29
{
30
30
try
31
31
{
32
+ if ( inputStream . Length < 1 )
33
+ {
34
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogError ( "The incomming message was too small" ) ;
35
+ messageType = MLAPIConstants . INVALID ;
36
+ return null ;
37
+ }
38
+
32
39
bool isEncrypted = inputHeaderReader . ReadBit ( ) ;
33
40
bool isAuthenticated = inputHeaderReader . ReadBit ( ) ;
34
41
@@ -89,7 +96,15 @@ internal static BitStream UnwrapMessage(BitStream inputStream, uint clientId, ou
89
96
90
97
if ( isEncrypted )
91
98
{
92
- inputStream . Read ( IV_BUFFER , 0 , IV_BUFFER . Length ) ;
99
+ int ivRead = inputStream . Read ( IV_BUFFER , 0 , IV_BUFFER . Length ) ;
100
+
101
+ if ( ivRead != IV_BUFFER . Length )
102
+ {
103
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogError ( "Invalid IV size" ) ;
104
+ messageType = MLAPIConstants . INVALID ;
105
+ return null ;
106
+ }
107
+
93
108
PooledBitStream outputStream = PooledBitStream . Get ( ) ;
94
109
95
110
using ( RijndaelManaged rijndael = new RijndaelManaged ( ) )
@@ -114,6 +129,14 @@ internal static BitStream UnwrapMessage(BitStream inputStream, uint clientId, ou
114
129
}
115
130
116
131
outputStream . Position = 0 ;
132
+
133
+ if ( outputStream . Length == 0 )
134
+ {
135
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogError ( "The incomming message was too small" ) ;
136
+ messageType = MLAPIConstants . INVALID ;
137
+ return null ;
138
+ }
139
+
117
140
int msgType = outputStream . ReadByte ( ) ;
118
141
messageType = msgType == - 1 ? MLAPIConstants . INVALID : ( byte ) msgType ;
119
142
}
@@ -122,6 +145,13 @@ internal static BitStream UnwrapMessage(BitStream inputStream, uint clientId, ou
122
145
}
123
146
else
124
147
{
148
+ if ( inputStream . Length - inputStream . Position <= 0 )
149
+ {
150
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogError ( "The incomming message was too small" ) ;
151
+ messageType = MLAPIConstants . INVALID ;
152
+ return null ;
153
+ }
154
+
125
155
int msgType = inputStream . ReadByte ( ) ;
126
156
messageType = msgType == - 1 ? MLAPIConstants . INVALID : ( byte ) msgType ;
127
157
return inputStream ;
0 commit comments