* Fix bug ID #32025

git-svn-id: trunk@36704 -
This commit is contained in:
michael 2017-07-09 09:10:53 +00:00
parent f247a66c90
commit 31d9d345e1
10 changed files with 110 additions and 54 deletions

View File

@ -1,7 +1,8 @@
{$mode objfpc}{$h+}
program Drawing;
uses cwstring,classes, sysutils, FPImage, FPCanvas, FPImgCanv, FPWritePNG, FPReadPNG;
uses
{$IFDEF UNIX}cwstring,{$ENDIF} classes, sysutils, FPImage, FPCanvas, FPImgCanv, FPWritePNG, FPReadPNG;
const
MyColor : TFPColor = (Red: $7FFF; Green: $0000; Blue: $FFFF; Alpha: alphaOpaque);

View File

@ -3,7 +3,7 @@
program textout;
uses
cwstring,classes, sysutils, FPImage, FPCanvas, FPImgCanv, ftFont, FPWritePNG, freetype;
{$IFDEF UNIX}cwstring, {$ENDIF} classes, sysutils, FPImage, FPCanvas, FPImgCanv, ftFont, FPWritePNG, freetype;
const
MyColor : TFPColor = (Red: $7FFF; Green: $0000; Blue: $FFFF; Alpha: alphaOpaque);

View File

@ -124,7 +124,6 @@ begin
try
if CheckContents (str) then
try
str.Position := startPos;
FStream := str;
FImage := self;
InternalRead (str, self);

View File

@ -224,7 +224,7 @@ begin
end;
procedure TFPReaderBMP.InternalRead(Stream:TStream; Img:TFPCustomImage);
// NOTE: Assumes that BMP header already has been read
Var
Row, i, pallen : Integer;
BadCompression : boolean;
@ -504,16 +504,23 @@ begin
end;
function TFPReaderBMP.InternalCheck (Stream:TStream) : boolean;
// NOTE: Does not rewind the stream!
var
BFH:TBitMapFileHeader;
n: Int64;
begin
stream.Read(BFH,SizeOf(BFH));
{$IFDEF ENDIAN_BIG}
SwapBMPFileHeader(BFH);
{$ENDIF}
With BFH do
Result:=(bfType=BMmagic); // Just check magic number
Result:=False;
if Stream=nil then
exit;
n:=SizeOf(BFH);
Result:=Stream.Read(BFH,n)=n;
if Result then
begin
{$IFDEF ENDIAN_BIG}
SwapBMPFileHeader(BFH);
{$ENDIF}
Result := BFH.bfType = BMmagic; // Just check magic number
end;
end;
initialization

View File

@ -473,17 +473,23 @@ begin
end;
function TFPReaderGif.InternalCheck(Stream: TStream): boolean;
var
OldPos: Int64;
n: Int64;
begin
Result:=False;
if Stream = nil then
exit;
OldPos:=Stream.Position;
try
OldPos:=Stream.Position;
Stream.Read(FHeader,SizeOf(FHeader));
Result:=(FHeader.Signature = 'GIF') and
((FHeader.Version = '87a') or (FHeader.Version = '89a'));
Stream.Position:=OldPos;
except
Result:=False;
n := SizeOf(FHeader);
Result:=(Stream.Read(FHeader,n)=n)
and (FHeader.Signature = 'GIF')
and ((FHeader.Version = '87a') or (FHeader.Version = '89a'));
finally
Stream.Position := OldPos;
end;
end;

View File

@ -301,10 +301,28 @@ begin
end;
function TFPReaderPCX.InternalCheck(Stream: TStream): boolean;
var
hdr: TPcxHeader;
n: Integer;
oldPos: Int64;
begin
Result := True;
Result:=False;
if Stream = nil then
exit;
oldPos := Stream.Position;
try
n:=SizeOf(hdr);
Result:=(Stream.Read(hdr, n)=n)
and (hdr.FileID in [$0A, $0C])
and (hdr.ColorPlanes in [1, 3, 4])
and (hdr.Version in [0, 2, 3, 5])
and (hdr.PaletteType in [1, 2]);
finally
Stream.Position := oldPos;
end;
end;
initialization
ImageHandlers.RegisterImageReader('PCX Format', 'pcx', TFPReaderPCX);
end.

View File

@ -805,6 +805,7 @@ begin
raise PNGImageException.Create('Critical chunk '+chunk.readtype+' not recognized');
end;
// NOTE: It is assumed that signature and IDHDR chunk already have been read.
procedure TFPReaderPNG.InternalRead (Str:TStream; Img:TFPCustomImage);
begin
{$ifdef FPC_Debug_Image}
@ -872,33 +873,34 @@ begin
Result.Y := Height;
end;
// NOTE: Stream does not rewind here!
function TFPReaderPNG.InternalCheck (Str:TStream) : boolean;
var SigCheck : array[0..7] of byte;
r : integer;
begin
try
// Check Signature
Str.Read(SigCheck, SizeOf(SigCheck));
for r := 0 to 7 do
Result:=False;
if Str=Nil then
exit;
// Check Signature
if Str.Read(SigCheck, SizeOf(SigCheck)) <> SizeOf(SigCheck) then
Exit;
for r := 0 to 7 do
begin
If SigCheck[r] <> Signature[r] then
Exit(false);
If SigCheck[r] <> Signature[r] then
Exit;
end;
// Check IHDR
ReadChunk;
move (chunk.data^, FHeader, sizeof(Header));
with header do
begin
{$IFDEF ENDIAN_LITTLE}
Width := swap(width);
height := swap (height);
{$ENDIF}
result :=(width > 0) and (height > 0) and (compression = 0)
and (filter = 0) and (Interlace in [0,1]);
end;
// Check IHDR
ReadChunk;
move (chunk.data^, FHeader, sizeof(Header));
with header do
begin
{$IFDEF ENDIAN_LITTLE}
Width := swap(width);
height := swap (height);
{$ENDIF}
result := (width > 0) and (height > 0) and (compression = 0)
and (filter = 0) and (Interlace in [0,1]);
end;
except
result := false;
end;
end;
initialization

View File

@ -48,14 +48,32 @@ type
implementation
function TFPReaderPNM.InternalCheck(Stream:TStream):boolean;
begin
InternalCheck:=True;
end;
const
WhiteSpaces=[#9,#10,#13,#32]; {Whitespace (TABs, CRs, LFs, blanks) are separators in the PNM Headers}
WhiteSpaces=[#9,#10,#13,#32];
{Whitespace (TABs, CRs, LFs, blanks) are separators in the PNM Headers}
{ The magic number at the beginning of a pnm file is 'P1', 'P2', ..., 'P7'
followed by a WhiteSpace character }
function TFPReaderPNM.InternalCheck(Stream:TStream):boolean;
var
hdr: array[0..2] of char;
oldPos: Int64;
n: Integer;
begin
Result:=False;
if Stream = nil then
exit;
oldPos := Stream.Position;
try
n := SizeOf(hdr);
Result:=(Stream.Read(hdr[0], n) = n)
and (hdr[0] = 'P')
and (hdr[1] in ['1'..'7'])
and (hdr[2] in WhiteSpaces);
finally
Stream.Position := oldPos;
end;
end;
function DropWhiteSpaces(Stream : TStream) :Char;

View File

@ -588,14 +588,19 @@ end;
function TFPReaderPSD.InternalCheck(Stream: TStream): boolean;
var
OldPos: Int64;
n: Integer;
begin
Result:=False;
if Stream=Nil then
exit;
OldPos := Stream.Position;
try
OldPos:=Stream.Position;
Stream.Read(FHeader,SizeOf(FHeader));
Result:=(FHeader.Signature = '8BPS');
Stream.Position:=OldPos;
except
Result:=False;
n := SizeOf(FHeader);
Result:=(Stream.Read(FHeader, n) = n)
and (FHeader.Signature = '8BPS')
finally
Stream.Position := OldPos;
end;
end;

View File

@ -39,7 +39,7 @@ type
implementation
const
WhiteSpace = ' '#8#10#13;
WhiteSpace = ' '#9#10#13;
constructor TFPReaderXPM.create;
begin