If I have:
procedure TFServer.IdTCPServerExecute(AContext: TIdContext);
begin
...
size:=AContext.Connection.IOHandler.ReadLongInt;
Context.Connection.IOHandler.ReadStream(msgStream, size);
...
end;
it is all ok if my client send data with IdTCPClient.IOHandler.Write(MemoryStream1,0,True)
but if the client send data with IdTCPClient.IOHandler.WriteLn(string_message)
the IdTCPServer crash trying to execute Context.Connection.IOHandler.ReadStream(msgStream,size)
.
Obviously I don’t mix these calls but I would like to know how to properly handle this type of problem in case of malicious clients. More generally, how can you properly handle clients sending data of unknown format and length?