Core/Networking: Fixed possible buffer overflows in WorldSocket::WritePacketToBuffer

Closes #28370
This commit is contained in:
Shauren
2022-10-16 16:31:58 +02:00
parent 641390dca2
commit af76b41ace

View File

@@ -203,10 +203,11 @@ bool WorldSocket::Update()
MessageBuffer buffer(_sendBufferSize);
while (_bufferQueue.Dequeue(queued))
{
uint32 packetSize = queued->size();
uint32 packetSize = queued->size() + 2 /*opcode*/;
if (packetSize > MinSizeForCompression && queued->NeedsEncryption())
packetSize = compressBound(packetSize) + sizeof(CompressedWorldPacket);
packetSize = deflateBound(_compressionStream, packetSize) + sizeof(CompressedWorldPacket);
// Flush current buffer if too small for next packet
if (buffer.GetRemainingSpace() < packetSize + sizeof(PacketHeader))
{
QueuePacket(std::move(buffer));
@@ -215,7 +216,7 @@ bool WorldSocket::Update()
if (buffer.GetRemainingSpace() >= packetSize + sizeof(PacketHeader))
WritePacketToBuffer(*queued, buffer);
else // single packet larger than 4096 bytes
else // single packet larger than _sendBufferSize
{
MessageBuffer packetBuffer(packetSize + sizeof(PacketHeader));
WritePacketToBuffer(*queued, packetBuffer);