[eog] eog-scroll-view.c: guard against attempting to create a surface using an invalid size.



commit f7b8fe98144135ac2b29505df660245f8a937403
Author: Michael Webster <miketwebster gmail com>
Date:   Sun Jan 5 22:14:23 2020 -0500

    eog-scroll-view.c: guard against attempting to create a surface using an invalid size.
    
    Return an empty surface if this happens, and log a warning.

 src/eog-scroll-view.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/src/eog-scroll-view.c b/src/eog-scroll-view.c
index 42704c97..b0f3152c 100644
--- a/src/eog-scroll-view.c
+++ b/src/eog-scroll-view.c
@@ -45,6 +45,9 @@
 /* Time used for the realing animation of the overlaid buttons */
 #define OVERLAY_REVEAL_ANIM_TIME (500U) /* ms */
 
+/* from cairo-image-surface.c */
+#define MAX_IMAGE_SIZE 32767
+
 /* Signal IDs */
 enum {
        SIGNAL_ZOOM_CHANGED,
@@ -206,12 +209,29 @@ create_surface_from_pixbuf (EogScrollView *view, GdkPixbuf *pixbuf)
 {
        cairo_surface_t *surface;
        cairo_t *cr;
+       gint w, h;
+       gboolean size_invalid = FALSE;
+
+       w = gdk_pixbuf_get_width (pixbuf);
+       h = gdk_pixbuf_get_height (pixbuf);
+
+       if (w > MAX_IMAGE_SIZE || h > MAX_IMAGE_SIZE) {
+               g_warning ("Image dimensions too large to process");
+               w = 50;
+               h = 50;
+               size_invalid = TRUE;
+       }
 
        surface = gdk_window_create_similar_surface (gtk_widget_get_window (view->priv->display),
                                                     CAIRO_CONTENT_COLOR | CAIRO_CONTENT_ALPHA,
-                                                    gdk_pixbuf_get_width (pixbuf),
-                                                    gdk_pixbuf_get_height (pixbuf));
+                                                    w, h);
+
+       if (size_invalid) {
+               return surface;
+       }
+
        cairo_surface_set_device_scale (surface, 1.0, 1.0);
+
        cr = cairo_create (surface);
        gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
        cairo_paint (cr);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]