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

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy