Note: Not really a threat as buffer sizes are guaranteed to be Max MTU, but this should still be corrected.
// Example: Packet is 500 bytes, buffer is 400 bytes
if (len < data.Length)
{
// Current read: only reads first 400 bytes
// (incomplete/garbage if using DTLS)
// The Bug: the remaining 100 bytes of Packet A are saved
ReceivedDataCollection.Add(leftover100Bytes);
}
// RESULT: On the next read, the data stream looks like:
// [100 bytes from Packet A] + [start of Packet B]
Note: Not really a threat as buffer sizes are guaranteed to be Max MTU, but this should still be corrected.