st: Avoid integer overflow on unpremultiply

When computing the effective border color, we operate on colors with
premultiplied alpha to simplify the calculations, then unpremultiply
the result. However we miss a bounds check in the last check, so any
color component can overflow the allowed maximum of 0xff and shift the
result in unexpected ways.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/305
This commit is contained in:
Florian Müllner 2018-11-22 20:41:44 +01:00 committed by Florian Müllner
parent 6743c18fdf
commit 925a25da17

View File

@ -229,9 +229,9 @@ unpremultiply (ClutterColor *color)
{ {
if (color->alpha != 0) if (color->alpha != 0)
{ {
color->red = (color->red * 255 + 127) / color->alpha; color->red = MIN((color->red * 255 + 127) / color->alpha, 255);
color->green = (color->green * 255 + 127) / color->alpha; color->green = MIN((color->green * 255 + 127) / color->alpha, 255);
color->blue = (color->blue * 255 + 127) / color->alpha; color->blue = MIN((color->blue * 255 + 127) / color->alpha, 255);
} }
} }