Found problem in unreliable fragmented message receive

17 views
Skip to first unread message

David Almroth

unread,
Oct 15, 2010, 1:24:00 PM10/15/10
to lidgren-network, pikk...@googlegroups.com
Hi master Lidgren,

I've done some extensive test with sending av receiving fragmented
messages over the unreliable channel.
In one of my tests i send the last fragment first.
This gives me a crash bug.

From what I can see this part of the code (lidgren generation 2)
is the problem.

As you can see below, the space for all fragmens' payload is allocated
based on the size of the first arriving
fragment. If the first arriving fragment is shorter than the rest of
the fragments the Array.Copy() in AcceptMessage(IncomingNetMessage
msg) will crash when the other fragments arrive later.
The last fragment is usually shorter than the other fragments. Make a
test and send the last (short) fragment first and you will see this
bug.

Code sample from NetConnection.Fragmentation.cs:

if (!m_fragments.TryGetValue(id, out fmsg))
{
m_owner.LogVerbose("Creating new FragmentMessage instance for id "
+ id);
fmsg = new FragmentedMessage();
fmsg.TotalFragments = total;
fmsg.FragmentsReceived = 0;
fmsg.ChunkSize = payloadLen;
fmsg.Data = new byte[payloadLen * total]; //This is the
problem !!!
m_fragments[id] = fmsg;
}

My suggestion for a solution is to discard the complete fragmented
message if the last fragment arrives first. Since it is sent as
unreliable, it is OK to discard it.

Best Regards
/David


lidgren

unread,
Oct 15, 2010, 2:19:34 PM10/15/10
to lidgren-network
Good catch; fixed in revision 291.

--michael

David Almroth

unread,
Oct 17, 2010, 12:25:22 PM10/17/10
to lidgren-network
Thanks!
Reply all
Reply to author
Forward
0 new messages