From edba707b32d47977e14f576854f61a0c1a569eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 28 Jun 2021 12:12:21 +0400 Subject: [PATCH spice-gtk] Fix potential div0 crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gdk_monitor_get_geometry() may return 0-size, and leads to crash: https://bugzilla.redhat.com/show_bug.cgi?id=1941627 Signed-off-by: Marc-André Lureau --- src/spice-widget.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/spice-widget.c b/src/spice-widget.c index 7ee02a8..afcf45a 100644 --- a/src/spice-widget.c +++ b/src/spice-widget.c @@ -1379,9 +1379,11 @@ static void recalc_geometry(GtkWidget *widget) width_mm = gdk_monitor_get_width_mm(monitor); gdk_monitor_get_geometry(monitor, &geometry); /* FIXME: gives wrong results atm: https://gitlab.gnome.org/GNOME/gtk/-/issues/3066 */ - width_mm = (width_mm * d->ww / geometry.width) / zoom * scale_factor; - height_mm = (height_mm * d->wh / geometry.height) / zoom * scale_factor; - has_display_mm = true; + if (geometry.width > 0 && geometry.height > 0) { + width_mm = (width_mm * d->ww / geometry.width) / zoom * scale_factor; + height_mm = (height_mm * d->wh / geometry.height) / zoom * scale_factor; + has_display_mm = true; + } } DISPLAY_DEBUG(display, -- 2.29.0