TFPReaderBMP.CheckContents incorrectly returns True for a text-file (if it's content starts with 'BM')
The following program classifies the attached text file as being a valid bitmap file:
{$mode objfpc}
{$h+}
uses
classes, fpreadbmp;
var
s : TStream;
Reader: TFPReaderBMP;
B: Boolean;
begin
s := TFileStream.Create('not-a-bmp.txt', fmOpenRead);
try
Reader := TFPReaderBMP.Create;
B := Reader.CheckContents(s);
if B then
writeln('FAIL: TFPReaderBMP.CheckContents: File "not-a-bmp.txt" is a Bitmap')
else
writeln('TFPReaderBMP.CheckContents: File "not-a-bmp.txt" is a NOT Bitmap [OK]');
finally
s.Free;
Reader.Free;
end;
end.
The textfile needs to beging with "BM" (without the quotes) and needst to be at least 14 bytes in size.
The test in FPReaderBMP.CheckContents is a bit rudimentary and could be extended somewhat to also check for the existence of a TBitmapInfo section and the sanity of that TBitmapInfo (does it have a valid BitmapHeaderSize and a valid BitsPerPixel).
As a side note: if I'm not mistaken then the "BMP magic word" can be either BM or BA?