From 7e20dce0699e9dcc9efae3e84fbfc34129e0b31e Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 24 Oct 2019 10:02:19 +0000 Subject: [PATCH] lazmapviewer: Fix crash when painting outside the buffer. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7168 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/lazmapviewer/source/mvde_intfgraphics.pas | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/components/lazmapviewer/source/mvde_intfgraphics.pas b/components/lazmapviewer/source/mvde_intfgraphics.pas index 165652374..2a27115ad 100644 --- a/components/lazmapviewer/source/mvde_intfgraphics.pas +++ b/components/lazmapviewer/source/mvde_intfgraphics.pas @@ -60,6 +60,11 @@ uses LCLType, FPImgCanv, GraphType; +function InRange(x, min, max: Integer): Boolean; +begin + Result := (x >= min) and (x <= max); +end; + {$IF Laz_FullVersion < 1090000} // Workaround for http://mantis.freepascal.org/view.php?id=27144 procedure CopyPixels(ASource, ADest: TLazIntfImage; @@ -164,6 +169,10 @@ begin for i := 0 to intfImg.Width - 1 do begin cimg := intfImg.Colors[i, j]; alpha := cimg.Alpha / word($FFFF); + if not InRange(i + X, 0, FBuffer.Width-1) then + Continue; + if not InRange(j + Y, 0, FBuffer.Height-1) then + Continue; cbuf := FBuffer.Colors[i + X, j + Y]; cbuf.Red := Round(alpha * cimg.Red + (1 - alpha) * cbuf.Red); cbuf.Green := Round(alpha * cimg.Green + (1 - alpha) * cbuf.Green); @@ -173,7 +182,8 @@ begin end else for j := 0 to intfImg.Height - 1 do for i := 0 to intfImg.Width - 1 do - FBuffer.Colors[i + X, j + Y] := intfImg.Colors[i, j]; + if InRange(i + x, 0, FBuffer.Width-1) and InRange(j + Y, 0, FBuffer.Height-1) then + FBuffer.Colors[i + X, j + Y] := intfImg.Colors[i, j]; finally intfimg.Free; end;