-
Notifications
You must be signed in to change notification settings - Fork 141
bugfix(network): Fix packet size setup mistakes #2040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix(network): Fix packet size setup mistakes #2040
Conversation
|
Can you describe the implications of this change? What does it fix in practice and can it be user facing at all? |
There should be no practical change, and no user facing change. In theory, when a message is too large, the wrapper path uses sizeof(struct) which would cause problems when it's wrong.
That said, keeping the bug makes the serialization /deserialization code messier and hacky. We have to write the struct and then manually add the commandId, instead of just writing the struct. #1680 will be simpler after this fix |
|
Are you very sure this causes no runtime issues? UnsignedInt bufferSize = GetBufferSizeNeededForCommand(msg); // <---- expects good size
bigPacketData = NEW UnsignedByte[bufferSize]; // <---- allocates with size
FillBufferWithCommand(bigPacketData, ref); // <---- writes to sized bufferWouldn't the write overflow the buffer if it was too small? |
|
Yes exactly. The reason there's no runtime issue is that ConstructBigCommandPacketList is only called when packet->addCommand() returns false (message too large for single packet). In other words, I think this is a problematic bug that went unnoticed because the message sizes are just never too big. Do you see any downsides to fixing it? |
|
Hmm ok maybe I wonder how the
No. I am just trying to understand if this will fix anything user facing. |
Yes, file transfers use the big packet flow, but those sizes are correct - the bug was only in LoadComplete/TimeOutGameStart which never use the big packet path. The isRoomFor* functions do similar work, but they handle the conditional inclusion of things like 'Did this change since the last message?' - while looking, I noticed they actually had the same bugs (missing CommandId counting), now fixed. Again, it never mattered for these messages because it's like 10 bytes being checked if it fits in 512 byte packets. |
xezon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have promoted this to bug fix because in theory this can corrupt memory, but is probably very unlikely (or even impossible) in practice. Basically a packet would have to be filled just enough for one of the missized packets to pass the incorrect size check, while their written contents would then exceed the packet buffer.
I hope we can consolidate these packet size code paths because this setup is just awful.
Fixes latent bugs in network packet size calculations
Changes
Fix struct sizes (
NetPacketStructs.h)commandIdfield toNetPacketLoadCompleteMessageandNetPacketTimeOutGameStartMessageaverageFpsfromUnsignedBytetoUnsignedShortinNetPacketRunAheadMetricsCommandFix
isRoomFor*functions (NetPacket.cpp)isRoomForLoadCompleteMessageandisRoomForTimeOutGameStartMessageFix wrong function call (
NetPacket.cpp)addTimeOutGameStartMessagenow callsisRoomForTimeOutGameStartMessageinstead ofisRoomForLoadCompleteMessage(These are accidentally/coincidentally identical, but it's now using the right one)