1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-21 22:13:07 +01:00

Fix potential crash on corrupted network data

This commit is contained in:
ZehMatt
2021-08-06 18:16:24 +03:00
parent 40a4a993de
commit 87fbb9faf5
3 changed files with 23 additions and 10 deletions

View File

@@ -61,13 +61,14 @@ NetworkReadPacket NetworkConnection::ReadPacket()
// NOTE: For compatibility reasons for the master server we need to remove sizeof(Header.Id) from the size.
// Previously the Id field was not part of the header rather part of the body.
header.Size -= sizeof(header.Id);
header.Size -= std::min<uint16_t>(header.Size, sizeof(header.Id));
// Fall-through: Read rest of packet.
}
// Read packet body.
{
// NOTE: BytesTransfered includes the header length, this will not underflow.
const size_t missingLength = header.Size - (InboundPacket.BytesTransferred - sizeof(header));
uint8_t buffer[NetworkBufferSize];