From bb14c5f69b0efb4b3206204a23b08f87ab828aef Mon Sep 17 00:00:00 2001 From: Steve Browne Date: Mon, 6 Jan 2020 09:09:00 -0500 Subject: [PATCH] Preserve mask when copying wxBitmapRefData to avoid crashes This crash was introduced in 2d15218c9db91d348e8c3a1c8e4a2a968bf3c70a and could happens inside wxBitmap::MSWBlendMaskWithAlpha() because the code checked for a mask and alpha, but the mask could be lost after AllocExclusive(). In practice, this happened e.g. when using 16-bit color as is the case for Windows 7 Hyper-V VMs. Closes https://github.com/wxWidgets/wxWidgets/pull/1695 --- src/msw/bitmap.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 4c34a6d109..194846e44c 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -223,10 +223,6 @@ wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData& data) { Init(); - // (deep) copy the mask if present - if (data.m_bitmapMask) - m_bitmapMask = new wxMask(*data.m_bitmapMask); - #if wxUSE_WXDIB wxASSERT_MSG( !data.m_dib, wxT("can't copy bitmap locked for raw access!") ); @@ -261,6 +257,11 @@ wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData& data) } } #endif // wxUSE_WXDIB + + // Ensure this is done after the block above otherwise if the color depth didn't match we'll lose the mask + // (deep) copy the mask if present + if (data.m_bitmapMask) + m_bitmapMask = new wxMask(*data.m_bitmapMask); } void wxBitmapRefData::Free()