TStrings is no longer able to load files of more than 2GB
Original Reporter info from Mantis: PascalR @PascalRiekenberg
-
Reporter name: Pascal Riekenberg
Original Reporter info from Mantis: PascalR @PascalRiekenberg
- Reporter name: Pascal Riekenberg
Description:
IIRC in the past i was abe to load a 8 GB file into SynEdit. This
is no longer possible as SetLength in TStrings.LoadFromStream only handles
parameter integer (32bit signed). -> Range Check Error
Additional information:
Procedure TStrings.LoadFromStream(Stream: TStream; AEncoding: TEncoding);
{
Borlands method is no good, since a pipe for
instance doesn't have a size.
So we must do it the hard way.
}
Const
BufSize = 1024;
MaxGrow = 1 shl 29;
Var
Buffer : TBytes;
T : string;
BytesRead,
BufLen,
I,BufDelta,
PreambleLength : Longint;
begin
// reread into a buffer
beginupdate;
try
SetLength(Buffer,0);
BufLen:=0;
I:=1;
Repeat
BufDelta:=BufSize*I;
SetLength(Buffer,BufLen+BufDelta); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Range Check Error here!
BytesRead:=Stream.Read(Buffer[BufLen],BufDelta);
inc(BufLen,BufDelta);
If I<MaxGrow then
I:=I shl 1;
Until BytesRead<>BufDelta;
SetLength(Buffer,BufLen-BufDelta+BytesRead);
PreambleLength:=TEncoding.GetBufferEncoding(Buffer,AEncoding,FDefaultEncoding);
T:=AEncoding.GetAnsiString(Buffer,PreambleLength,Length(Buffer)-PreambleLength);
SetEncoding(AEncoding);
SetLength(Buffer,0);
SetTextStr(T);
finally
EndUpdate;
end;
end;
Mantis conversion info:
- Mantis ID: 33844
- OS: Windows 10 x64
- OS Build: 1803
- Platform: i386
- Monitored by: » Vincent (Vincent Snijders)