Skip to content

Commit 27e26a6

Browse files
committed
fix: crash in OpenTextFile, for a 0-bytes file - override the encoding to one without BOM
Closes #1448
1 parent be5322c commit 27e26a6

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

source/apphelpers.pas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,9 @@ procedure OpenTextFile(const Filename: String; out Stream: TFileStream; var Enco
13401340
Stream := TFileStream.Create(Filename, fmOpenRead or fmShareDenyNone);
13411341
if Encoding = nil then
13421342
Encoding := DetectEncoding(Stream);
1343+
// For a 0-bytes file, override the encoding to one without BOM
1344+
if _GetFileSize(Filename) < Length(Encoding.GetPreamble) then
1345+
Encoding := UTF8NoBOMEncoding;
13431346
// If the file contains a BOM, advance the stream's position
13441347
BomLen := 0;
13451348
if Length(Encoding.GetPreamble) > 0 then begin

0 commit comments

Comments
 (0)