You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Detection and graceful handling of corrupt packets (#2419)
* fix: Detection and graceful handling of corrupt packets
Adds multiple ways to detect and handle corrupt packets that could otherwise cause issues and put the game into a bad state, or potentially cause crashes:
- A "magic" value at the start of each packet helps when looking at packet dumps to see where potential start-of-packet is if the data gets offset (as was seen in the recent BatchSendQueue corruption bug)
- A "size in bytes" value helps us detect if the packet has been truncated or if garbage has been added to the end
- A "hash" value helps to detect when the other values are correct but one or more bytes within the packet have been corrupted
Additionally, code has been added to refuse to process ConnectionRequestMessage or ConnectionAcceptedMessage on an alredy-established connection, or either of those being received by the wrong side, as those could otherwise be used as a vector for attack by a malicious actor and render the framework completely broken.
In all cases, if these issues occur, the log requests the user to file an issue with us with the full hex dump of the packet that was received.
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,8 @@ Additional documentation and release notes are available at [Multiplayer Documen
10
10
11
11
### Added
12
12
13
+
- Added detection and graceful handling of corrupt packets for additional safety. (#2419)
14
+
13
15
### Changed
14
16
15
17
- The UTP component UI has been updated to be more user-friendly for new users by adding a simple toggle to switch between local-only (127.0.0.1) and remote (0.0.0.0) binding modes, using the toggle "Allow Remote Connections" (#2408)
NetworkLog.LogWarning($"Message received from {nameof(senderId)}={senderId} before it has been accepted");
150
+
if(NetworkLog.CurrentLogLevel<=LogLevel.Normal)
151
+
{
152
+
NetworkLog.LogError($"A {nameof(ConnectionApprovedMessage)} was received from a client on the server side. This should not happen. Please report this to the Netcode for GameObjects team at https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues and include the following data: Message Size: {messageContent.Length}. Message Content: {MessagingSystem.ByteArrayToString(messageContent.ToArray(),0,messageContent.Length)}");
NetworkLog.LogError($"A {nameof(ConnectionRequestMessage)} was received from a client when the connection has already been established. This should not happen. Please report this to the Netcode for GameObjects team at https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues and include the following data: Message Size: {messageContent.Length}. Message Content: {MessagingSystem.ByteArrayToString(messageContent.ToArray(),0,messageContent.Length)}");
172
+
}
173
+
174
+
returnfalse;
175
+
}
176
+
}
177
+
else
178
+
{
179
+
if(messageType==typeof(ConnectionRequestMessage))
180
+
{
181
+
if(NetworkLog.CurrentLogLevel<=LogLevel.Normal)
182
+
{
183
+
NetworkLog.LogError($"A {nameof(ConnectionRequestMessage)} was received from the server on the client side. This should not happen. Please report this to the Netcode for GameObjects team at https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues and include the following data: Message Size: {messageContent.Length}. Message Content: {MessagingSystem.ByteArrayToString(messageContent.ToArray(),0,messageContent.Length)}");
NetworkLog.LogError($"A {nameof(ConnectionApprovedMessage)} was received from the server when the connection has already been established. This should not happen. Please report this to the Netcode for GameObjects team at https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues and include the following data: Message Size: {messageContent.Length}. Message Content: {MessagingSystem.ByteArrayToString(messageContent.ToArray(),0,messageContent.Length)}");
NetworkLog.LogWarning("Received a packet too small to contain a BatchHeader. Ignoring it.");
229
+
NetworkLog.LogError("Received a packet too small to contain a BatchHeader. Ignoring it.");
218
230
return;
219
231
}
220
232
221
233
batchReader.ReadValue(outBatchHeaderbatchHeader);
222
234
235
+
if(batchHeader.Magic!=BatchHeader.MagicValue)
236
+
{
237
+
NetworkLog.LogError($"Received a packet with an invalid Magic Value. Please report this to the Netcode for GameObjects team at https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues and include the following data: Offset: {data.Offset}, Size: {data.Count}, Full receive array: {ByteArrayToString(data.Array,0,data.Array.Length)}");
238
+
return;
239
+
}
240
+
241
+
if(batchHeader.BatchSize!=data.Count)
242
+
{
243
+
NetworkLog.LogError($"Received a packet with an invalid Batch Size Value. Please report this to the Netcode for GameObjects team at https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues and include the following data: Offset: {data.Offset}, Size: {data.Count}, Expected Size: {batchHeader.BatchSize}, Full receive array: {ByteArrayToString(data.Array,0,data.Array.Length)}");
NetworkLog.LogError($"Received a packet with an invalid Hash Value. Please report this to the Netcode for GameObjects team at https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues and include the following data: Received Hash: {batchHeader.BatchHash}, Calculated Hash: {hash}, Offset: {data.Offset}, Size: {data.Count}, Full receive array: {ByteArrayToString(data.Array,0,data.Array.Length)}");
0 commit comments