From: Matthias Clasen Date: Fri, 27 May 2022 02:28:57 +0000 (-0400) Subject: wayland: Sanity check cursor image size X-Git-Tag: archive/raspbian/4.7.2+ds-3+rpi1^2^2~15^2~1^2~7^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c543206d791977b921a7952bb3cc4c65d9d29958;p=gtk4.git wayland: Sanity check cursor image size On Wayland it is a protocol violation to upload buffers with dimensions that are not an integer multiple of the buffer scale. Until recently, Mutter did not enforce this. When it started doing so, some users started seeing crashes in GTK apps because the cursor theme ended up with e.g. a 15x16 pixel image at scale of 2. Add a small sanity check for this case. --- diff --git a/gdk/wayland/gdkcursor-wayland.c b/gdk/wayland/gdkcursor-wayland.c index c859f3ccac..a5602bcbaf 100644 --- a/gdk/wayland/gdkcursor-wayland.c +++ b/gdk/wayland/gdkcursor-wayland.c @@ -178,6 +178,7 @@ _gdk_wayland_cursor_get_buffer (GdkWaylandDisplay *display, if (c) { struct wl_cursor_image *image; + int cursor_scale; if (image_index >= c->image_count) { @@ -189,12 +190,22 @@ _gdk_wayland_cursor_get_buffer (GdkWaylandDisplay *display, image = c->images[image_index]; - *hotspot_x = image->hotspot_x / desired_scale; - *hotspot_y = image->hotspot_y / desired_scale; + cursor_scale = desired_scale; + if ((image->width % cursor_scale != 0) || + (image->height % cursor_scale != 0)) + { + g_warning (G_STRLOC " cursor image size (%dx%d) not an integer" + "multiple of scale (%d)", image->width, image->height, + cursor_scale); + cursor_scale = 1; + } + + *hotspot_x = image->hotspot_x / cursor_scale; + *hotspot_y = image->hotspot_y / cursor_scale; - *width = image->width / desired_scale; - *height = image->height / desired_scale; - *scale = desired_scale; + *width = image->width / cursor_scale; + *height = image->height / cursor_scale; + *scale = cursor_scale; return wl_cursor_image_get_buffer (image); }