Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ bool CGame::StaticProcessNetworkPacket(unsigned char ucPacketID, const NetServer
{
if (ucPacketID == PACKET_ID_LUA_EVENT)
{
if (pBitStream->GetNumberOfUnreadBits() > CLuaEventPacket::MAX_LUA_EVENT_ARGUMENTS_SIZE * 8)
if (pBitStream->GetNumberOfUnreadBits() > (CLuaEventPacket::MAX_LUA_EVENT_ARGUMENTS_SIZE + CLuaEventPacket::LUA_EVENT_ENVELOPE_HEADROOM) * 8)
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/packets/CLuaEventPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool CLuaEventPacket::Read(NetBitStreamInterface& BitStream)
{
if (usNameLength < (MAX_EVENT_NAME_LENGTH - 1) && BitStream.ReadStringCharacters(m_strName, usNameLength) && BitStream.Read(m_ElementID))
{
if (BitStream.GetNumberOfUnreadBits() > MAX_LUA_LATENT_EVENT_ARGUMENTS_SIZE * 8)
if (BitStream.GetNumberOfUnreadBits() > (MAX_LUA_LATENT_EVENT_ARGUMENTS_SIZE + LUA_EVENT_ENVELOPE_HEADROOM) * 8)
return false;

// Faster than using a constructor
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/packets/CLuaEventPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class CLuaEventPacket final : public CPacket
{
public:
static constexpr int LUA_EVENT_ENVELOPE_HEADROOM = 64 * 1024;
// Limit for the size of the arguments in a single triggerEvent. (1MB)
static constexpr int MAX_LUA_EVENT_ARGUMENTS_SIZE = 1024 * 1024;
// Limit for the size of the arguments in a single triggerLatentEvent. (10MB)
Expand Down
16 changes: 8 additions & 8 deletions Shared/mods/deathmatch/logic/CLatentReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,10 @@ void CLatentReceiver::OnReceive(NetBitStreamInterface* pBitStream)
if (uiFinalSize > 100 * 1024 * 1024)
return OnReceiveError("uiFinalSize too large");

// CATEGORY_PACKET reassembles raw packet data and feeds it into
// the main packet dispatch (CGame::StaticProcessPacket). Without
// a tighter cap, an attacker can craft a 100MB payload targeting
// packet handlers that scale poorly with input size (e.g.
// CPlayerModInfoPacket). 10MB is well above any legitimate use.
constexpr uint LATENT_PACKET_MAX_SIZE = 10 * 1024 * 1024;
// uiFinalSize includes the 5-byte CATEGORY_PACKET wrapper and the
// serialized event envelope. Keep 10 MiB available for argument data
// while allowing a small amount of protocol overhead.
constexpr uint LATENT_PACKET_MAX_SIZE = 10 * 1024 * 1024 + 64 * 1024;
if (usCategory == CATEGORY_PACKET && uiFinalSize > LATENT_PACKET_MAX_SIZE)
return OnReceiveError("CATEGORY_PACKET payload too large");

Expand All @@ -159,8 +157,10 @@ void CLatentReceiver::OnReceive(NetBitStreamInterface* pBitStream)
//
// Read body
//
if (activeRx.uiWritePosition + usSizeSent > activeRx.buffer.GetSize())
return OnReceiveError("Buffer would overflow");
if (activeRx.uiWritePosition > activeRx.buffer.GetSize() || usSizeSent > activeRx.buffer.GetSize() - activeRx.uiWritePosition)
{
return OnReceiveError(SString("Buffer would overflow (size:%u pos:%u chunk:%u)", activeRx.buffer.GetSize(), activeRx.uiWritePosition, usSizeSent));
}

if (bIsTail && activeRx.uiWritePosition + usSizeSent != activeRx.buffer.GetSize())
return OnReceiveError("Buffer size wrong");
Expand Down
Loading