From ec8bfbebdc74b07794ae607378e3e04a57e82f80 Mon Sep 17 00:00:00 2001 From: Eric Raijmakers Date: Thu, 1 Oct 2020 19:27:28 +0200 Subject: [PATCH] Fix wrong step size in wxImage::Paste() Fix a bug with wrong size passed to memset() introduced in 1f0ade29f0 (Fix using mask colour even if there is no mask in wxImage::Paste, 2020-09-30) which caused memory corruption and add a test (the one with the large negative vertical offset) allowing to reproduce this reliably. Closes https://github.com/wxWidgets/wxWidgets/pull/2067 --- src/common/image.cpp | 2 +- tests/image/image.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/common/image.cpp b/src/common/image.cpp index 8515cf4c3a..c62d0a909f 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -1764,7 +1764,7 @@ wxImage::Paste(const wxImage & image, int x, int y, // Make all the copied pixels fully opaque if (alpha_target_data != NULL) { - memset(alpha_target_data, wxALPHA_OPAQUE, target_alpha_step); + memset(alpha_target_data, wxALPHA_OPAQUE, width); alpha_target_data += target_alpha_step; } } diff --git a/tests/image/image.cpp b/tests/image/image.cpp index 3672a31ff5..9f72e942b2 100644 --- a/tests/image/image.cpp +++ b/tests/image/image.cpp @@ -1839,6 +1839,21 @@ TEST_CASE("wxImage::Paste", "[image][paste]") CHECK_THAT(actual, CenterAlphaPixelEquals(255)); CHECK_THAT(actual, RGBSameAs(black)); } + SECTION("Paste large image with negative vertical offset") + { + wxImage target(442, 249); + wxImage to_be_pasted(345, 24900); + target.InitAlpha(); + target.Paste(to_be_pasted, 48, -12325, wxIMAGE_ALPHA_BLEND_COMPOSE); + } + SECTION("Paste large image with negative horizontal offset") + { + wxImage target(249, 442); + wxImage to_be_pasted(24900, 345); + target.InitAlpha(); + target.Paste(to_be_pasted, -12325, 48, wxIMAGE_ALPHA_BLEND_COMPOSE); + } + } /*