From 9c83dd8d3e397b455bce69a9f4822d6fd55eaf83 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Thu, 24 Mar 2016 22:01:41 +0100 Subject: [PATCH] Added checking parameters of wxGDIPlusRenderer::CreateSubBitmap method. Check if source bitmap is valid and whether sub-bitmap is entirely within it. --- src/msw/graphics.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index da9da365da..2bb9b739cb 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -2387,9 +2387,16 @@ wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap ) wxGraphicsBitmap wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) { ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); + + wxCHECK_MSG(!bitmap.IsNull(), wxNullGraphicsBitmap, wxS("Invalid bitmap")); + Bitmap* image = static_cast(bitmap.GetRefData())->GetGDIPlusBitmap(); 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; p.SetRefData(new wxGDIPlusBitmapData( this , image->Clone( (REAL) x , (REAL) y , (REAL) w , (REAL) h , PixelFormat32bppPARGB) )); return p;