🚨 Validate packet lengths from the server
A declared length below the header size desynced the receive queue and dispatched handlers on garbage, and an unbounded length could grow the queue without limit.
This commit is contained in:
@@ -264,11 +264,17 @@ begin
|
|||||||
size := packetHandler.PacketLength;
|
size := packetHandler.PacketLength;
|
||||||
if size = 0 then
|
if size = 0 then
|
||||||
begin
|
begin
|
||||||
if FReceiveQueue.Size > 5 then
|
if FReceiveQueue.Size >= 5 then
|
||||||
size := FReceiveQueue.ReadCardinal
|
size := FReceiveQueue.ReadCardinal
|
||||||
else
|
else
|
||||||
Break; //wait for more data
|
Break; //wait for more data
|
||||||
end;
|
end;
|
||||||
|
if (size < 5) or (size > 32 * 1024 * 1024) then
|
||||||
|
begin
|
||||||
|
Disconnect;
|
||||||
|
FReceiveQueue.Clear;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
|
||||||
if FReceiveQueue.Size >= size then
|
if FReceiveQueue.Size >= size then
|
||||||
begin
|
begin
|
||||||
|
|||||||
Reference in New Issue
Block a user