fix: NetworkServer.OnTransportData header size is now checked before every message unpacking again like before batching.

This commit is contained in:
vis2k 2021-06-14 17:53:41 +08:00
parent e6b379fb8d
commit bdb410e015

View File

@ -429,13 +429,6 @@ internal static void OnTransportData(int connectionId, ArraySegment<byte> data,
{
if (connections.TryGetValue(connectionId, out NetworkConnectionToClient connection))
{
if (data.Count < MessagePacking.HeaderSize)
{
Debug.LogError($"NetworkServer: received Message was too short (messages should start with message id)");
connection.Disconnect();
return;
}
// client might batch multiple messages into one packet.
// feed it to the Unbatcher.
// NOTE: we don't need to associate a channelId because we
@ -455,8 +448,19 @@ internal static void OnTransportData(int connectionId, ArraySegment<byte> data,
while (!isLoadingScene &&
connection.unbatcher.GetNextMessage(out NetworkReader reader))
{
if (!UnpackAndInvoke(connection, reader, channelId))
break;
// enough to read at least header size?
if (reader.Remaining >= MessagePacking.HeaderSize)
{
if (!UnpackAndInvoke(connection, reader, channelId))
break;
}
// otherwise disconnect
else
{
Debug.LogError($"NetworkServer: received Message was too short (messages should start with message id). Disconnecting {connectionId}");
connection.Disconnect();
return;
}
}
}
else Debug.LogError("HandleData Unknown connectionId:" + connectionId);