🐛 Guard fixed-length stream reads against short data

ReadStringFixed returned uninitialized memory on short reads and
crashed on negative lengths from untrusted input.
This commit is contained in:
2026-11-15 22:06:50 +01:00
parent 1498437e26
commit 2bffd2204b
+7 -2
View File
@@ -468,10 +468,15 @@ begin
end; end;
function TStreamWrapper.ReadStringFixed(ALength: Integer): string; function TStreamWrapper.ReadStringFixed(ALength: Integer): string;
var
bytesRead: Integer;
begin begin
if not Assigned(FStream) then Exit(''); if (not Assigned(FStream)) or (ALength <= 0) then Exit('');
SetLength(Result, ALength); SetLength(Result, ALength);
FStream.Read(PChar(Result)^, ALength); FillChar(PChar(Result)^, ALength, 0);
bytesRead := FStream.Read(PChar(Result)^, ALength);
if bytesRead < ALength then
SetLength(Result, bytesRead);
end; end;
procedure TStreamWrapper.WriteBoolean(AValue: Boolean); procedure TStreamWrapper.WriteBoolean(AValue: Boolean);