Added checking parameters of wxGDIPlusRenderer::CreateSubBitmap method.

Check if source bitmap is valid and whether sub-bitmap is entirely within it.
This commit is contained in:
Artur Wieczorek
2016-03-24 22:01:41 +01:00
parent 5ea0a0f5f9
commit 9c83dd8d3e

View File

@@ -2387,9 +2387,16 @@ wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap )
wxGraphicsBitmap wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) wxGraphicsBitmap wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
wxCHECK_MSG(!bitmap.IsNull(), wxNullGraphicsBitmap, wxS("Invalid bitmap"));
Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bitmap.GetRefData())->GetGDIPlusBitmap(); Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bitmap.GetRefData())->GetGDIPlusBitmap();
if ( image ) if ( image )
{ {
wxCHECK_MSG( x >= 0.0 && y >= 0.0 && w > 0.0 && h > 0.0 &&
x + w <= image->GetWidth() && y + h <= image->GetHeight(),
wxNullGraphicsBitmap, wxS("Invalid bitmap region"));
wxGraphicsBitmap p; wxGraphicsBitmap p;
p.SetRefData(new wxGDIPlusBitmapData( this , image->Clone( (REAL) x , (REAL) y , (REAL) w , (REAL) h , PixelFormat32bppPARGB) )); p.SetRefData(new wxGDIPlusBitmapData( this , image->Clone( (REAL) x , (REAL) y , (REAL) w , (REAL) h , PixelFormat32bppPARGB) ));
return p; return p;