Skip to content

Bug in TFileIO.CheckBOM #139

Closed
Closed
@delphidabbler

Description

@delphidabbler

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;

Metadata

Metadata

Assignees

Labels

bugBug reportcompletedWork has been completed on this issue and changes have been committed to `develop` branch..

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions