Skip to content

Commit 487eada

Browse files
committed
Avoid overflow when calculating maxCapacity
1 parent b56e216 commit 487eada

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Unity.Collections;
1212
using Unity.Collections.LowLevel.Unsafe;
1313
using Unity.Jobs;
14+
using Unity.Mathematics;
1415
using Unity.Netcode.Runtime;
1516
using Unity.Networking.Transport;
1617
using Unity.Networking.Transport.Error;
@@ -1535,7 +1536,12 @@ public override void Send(ulong clientId, ArraySegment<byte> payload, NetworkDel
15351536
// the only case where a full send queue causes a connection loss. Full unreliable
15361537
// send queues are dealt with by flushing it out to the network or simply dropping
15371538
// new messages if that fails.
1538-
var maxCapacity = m_MaxSendQueueSize > 0 ? m_MaxSendQueueSize : m_DisconnectTimeoutMS * k_MaxReliableThroughput;
1539+
var maxCapacity = m_MaxSendQueueSize;
1540+
if (maxCapacity <= 0)
1541+
{
1542+
var fullCalculation = Math.BigMul(m_DisconnectTimeoutMS, k_MaxReliableThroughput);
1543+
maxCapacity = (int)Math.Max(fullCalculation, int.MaxValue);
1544+
}
15391545

15401546
queue = new BatchedSendQueue(Math.Max(maxCapacity, m_MaxPayloadSize));
15411547
m_SendQueue.Add(sendTarget, queue);

0 commit comments

Comments
 (0)