fix: crash in OpenTextFile, for a 0-bytes file - override the encoding to one without BOM

Closes #1448
This commit is contained in:
Ansgar Becker
2026-02-07 13:47:59 +01:00
parent 07f75f71d3
commit 4c179addec

View File

@@ -1331,6 +1331,9 @@ begin
Stream := TFileStream.Create(Filename, fmOpenRead or fmShareDenyNone);
if Encoding = nil then
Encoding := DetectEncoding(Stream);
// For a 0-bytes file, override the encoding to one without BOM
if _GetFileSize(Filename) < Length(Encoding.GetPreamble) then
Encoding := UTF8NoBOMEncoding;
// If the file contains a BOM, advance the stream's position
BomLen := 0;
if Length(Encoding.GetPreamble) > 0 then begin