LCL: Fix out-of-range access to Colors array in LazIntfImages.CopyPixels (Issue #27144).

git-svn-id: trunk@57653 -
This commit is contained in:
wp 2018-04-13 12:36:50 +00:00
parent f2f7e9c993
commit 68b3fe108b

View File

@ -3779,7 +3779,7 @@ procedure TLazIntfImage.CopyPixels(ASource: TFPCustomImage; XDst: Integer;
var var
SrcImg: TLazIntfImage absolute ASource; SrcImg: TLazIntfImage absolute ASource;
SrcHasMask, DstHasMask: Boolean; SrcHasMask, DstHasMask: Boolean;
x, y, xStop, yStop: Integer; x, y, xStart, yStart, xStop, yStop: Integer;
c: TFPColor; c: TFPColor;
begin begin
{ {
@ -3798,32 +3798,23 @@ begin
end; end;
// copy pixels // copy pixels
xStop := ASource.Width; XStart := IfThen(XDst < 0, -XDst, 0);
if Width - XDst < xStop YStart := IfThen(YDst < 0, -YDst, 0);
then xStop := Width - XDst; XStop := IfThen(Width - XDst < ASource.Width, Width - XDst, ASource.Width) - 1;
yStop := ASource.Height; YStop := IfTHen(Height - YDst < ASource.Height, Height - YDst, ASource.Height) - 1;
if Height - YDst < yStop
then yStop := Height - YDst;
Dec(xStop);
Dec(yStop);
if ASource is TLazIntfImage then
SrcHasMask := SrcImg.FRawImage.Description.MaskBitsPerPixel > 0
else
SrcHasMask := False;
SrcHasMask := (ASource is TLazIntfImage) and (SrcImg.FRawImage.Description.MaskBitsPerPixel > 0);
DstHasMask := FRawImage.Description.MaskBitsPerPixel > 0; DstHasMask := FRawImage.Description.MaskBitsPerPixel > 0;
if DstHasMask if DstHasMask and (ASource is TLazIntfImage)
and (ASource is TLazIntfImage)
then begin then begin
for y:=0 to yStop do for y:= yStart to yStop do
for x:=0 to xStop do for x:=xStart to xStop do
Masked[x+XDst,y+YDst] := SrcHasMask and SrcImg.Masked[x,y]; Masked[x+XDst,y+YDst] := SrcHasMask and SrcImg.Masked[x,y];
end; end;
for y:=0 to yStop do for y:=yStart to yStop do
for x:=0 to xStop do for x:=xStart to xStop do
begin begin
c := ASource.Colors[x,y]; c := ASource.Colors[x,y];