Skip to content

Commit 47028dd

Browse files
author
vis2k
committed
Common.ReadMessageBlocking: log warning instead of logging OverflowException if size header is negative
1 parent 1c1cdd9 commit 47028dd

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Telepathy/Common.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ protected static bool ReadMessageBlocking(NetworkStream stream, int MaxMessageSi
130130
// protect against allocation attacks. an attacker might send
131131
// multiple fake '2GB header' packets in a row, causing the server
132132
// to allocate multiple 2GB byte arrays and run out of memory.
133-
if (size <= MaxMessageSize)
133+
//
134+
// also protect against size <= 0 which would cause issues
135+
if (size > 0 && size <= MaxMessageSize)
134136
{
135137
// read exactly 'size' bytes for content (blocking)
136138
content = new byte[size];
137139
return stream.ReadExactly(content, size);
138140
}
139-
Logger.LogWarning("ReadMessageBlocking: possible allocation attack with a header of: " + size + " bytes.");
141+
Logger.LogWarning("ReadMessageBlocking: possible header attack with a header of: " + size + " bytes.");
140142
return false;
141143
}
142144

0 commit comments

Comments
 (0)