Closed
Description
TFileIO.CheckBOM
has a bug where it returns true for zero length preambles instead of false. Fixed this in cupola
as follows:
class function TFileIO.CheckBOM(const Stream: TStream;
const Encoding: TEncoding): Boolean;
var
Bytes: TBytes;
Preamble: TBytes;
OldPos: Int64;
begin
Assert(Assigned(Stream), 'TFileIO.CheckBOM: Stream is nil');
Assert(Assigned(Encoding), 'TFileIO.CheckBOM: Encoding is nil');
Preamble := Encoding.GetPreamble;
if Length(Preamble) = 0 then
Exit(False);
if Stream.Size < Length(Preamble) then
Exit(False);
OldPos := Stream.Position;
SetLength(Bytes, Length(Preamble));
Stream.Position := 0;
Stream.ReadBuffer(Pointer(Bytes)^, Length(Preamble));
Stream.Position := OldPos;
Result := IsEqualBytes(Bytes, Preamble);
end;