From 4c179addecc31446afe676d259732c5e075e505f Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sat, 7 Feb 2026 13:47:59 +0100 Subject: [PATCH] fix: crash in OpenTextFile, for a 0-bytes file - override the encoding to one without BOM Closes #1448 --- source/apphelpers.pas | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/apphelpers.pas b/source/apphelpers.pas index 3021c853..c7a4d61f 100644 --- a/source/apphelpers.pas +++ b/source/apphelpers.pas @@ -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