THRIFT-5619 make sure CheckReadBytesAvailable() and CountConsumedMessageBytes() handle negative sizes properly
Client: delphi
Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.Transport.pas b/lib/delphi/src/Thrift.Transport.pas
index 3f22b09..fd08837 100644
--- a/lib/delphi/src/Thrift.Transport.pas
+++ b/lib/delphi/src/Thrift.Transport.pas
@@ -596,7 +596,7 @@
procedure TEndpointTransportBase.CheckReadBytesAvailable( const numBytes : Int64);
// Throws if there are not enough bytes in the input stream to satisfy a read of numBytes bytes of data
begin
- if RemainingMessageSize < numBytes
+ if (RemainingMessageSize < numBytes) or (numBytes < 0)
then raise TTransportExceptionEndOfFile.Create('MaxMessageSize reached');
end;
@@ -604,7 +604,7 @@
procedure TEndpointTransportBase.CountConsumedMessageBytes( const numBytes : Int64);
// Consumes numBytes from the RemainingMessageSize.
begin
- if (RemainingMessageSize >= numBytes)
+ if (RemainingMessageSize >= numBytes) and (numBytes >= 0)
then Dec( FRemainingMessageSize, numBytes)
else begin
FRemainingMessageSize := 0;