Skip to content

Bug in TFileIO.CheckBOM #139

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
delphidabbler opened this issue Oct 20, 2024 · 2 comments
Closed

Bug in TFileIO.CheckBOM #139

delphidabbler opened this issue Oct 20, 2024 · 2 comments
Assignees
Labels
bug Bug report completed Work has been completed on this issue and changes have been committed to `develop` branch..

Comments

@delphidabbler
Copy link
Owner

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;
@delphidabbler delphidabbler self-assigned this Oct 20, 2024
@delphidabbler delphidabbler added accepted Accepted for implementation / fixing bug Bug report labels Oct 20, 2024
@github-project-automation github-project-automation bot moved this to Considering in CodeSnip Oct 20, 2024
@delphidabbler delphidabbler moved this from Considering to Accepted in CodeSnip Oct 20, 2024
@delphidabbler delphidabbler added this to the Planned for next patch milestone Oct 20, 2024
@delphidabbler
Copy link
Owner Author

This method is in UIOUtils

@delphidabbler delphidabbler added completed Work has been completed on this issue and changes have been committed to `develop` branch.. and removed accepted Accepted for implementation / fixing labels Oct 23, 2024
@delphidabbler delphidabbler moved this from Accepted to Done - awaiting release in CodeSnip Oct 23, 2024
@delphidabbler
Copy link
Owner Author

Implemented in commit 1ab44ec

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Bug report completed Work has been completed on this issue and changes have been committed to `develop` branch..
Projects
None yet
Development

No branches or pull requests

1 participant