Avoid division-by-zero in wxImage::Paste()

See #23791.

(cherry picked from commit 496a9a40a1853376d877a017a2b6b79b6d6b5f71)
This commit is contained in:
Paul Cornett 2023-08-23 23:03:43 -07:00 committed by Vadim Zeitlin
parent 2d3f193827
commit 60fe5c83a6
2 changed files with 9 additions and 0 deletions

View File

@ -269,6 +269,7 @@ All (GUI):
- Keep wxProgressDialog size when updating the message (Oleg Samarin, #23727).
- Fix crash when deleting selected item in wxGenericListCtrl (#23729).
- Use DIPs for toolbar image sizes in wxPropertyGrid.
- Fix undefined behaviour in wxImage::Paste() (aurel32, #23791).
wxGTK:

View File

@ -1740,6 +1740,14 @@ wxImage::Paste(const wxImage & image, int x, int y,
float light_left = (alpha_target_data[i] / 255.0f) * (1.0f - source_alpha);
float result_alpha = source_alpha + light_left;
alpha_target_data[i] = (unsigned char)((result_alpha * 255) + 0.5f);
if (result_alpha <= 0)
{
int c = 3 * i;
target_data[c++] = 0;
target_data[c++] = 0;
target_data[c] = 0;
continue;
}
for (int c = 3 * i; c < 3 * (i + 1); c++)
{
target_data[c] =