[gdk-pixbuf] ico: Try to skip over broken icon entries



commit be43c8f13751290c81f55336d4c08f4efc4fcd6e
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jul 13 22:17:49 2017 +0200

    ico: Try to skip over broken icon entries
    
    If an icon entry is broken, skip over it, but report the breakage if we
    could not find a single valid entry.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=776040

 gdk-pixbuf/io-ico.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)
---
diff --git a/gdk-pixbuf/io-ico.c b/gdk-pixbuf/io-ico.c
index e544464..12f0a58 100644
--- a/gdk-pixbuf/io-ico.c
+++ b/gdk-pixbuf/io-ico.c
@@ -225,6 +225,7 @@ static void DecodeHeader(guchar *Data, gint Bytes,
        gint I;
        guint16 imgtype; /* 1 = icon, 2 = cursor */
        GList *l;
+       gboolean got_broken_header = FALSE;
 
        /* Step 1: The ICO header */
 
@@ -310,6 +311,12 @@ static void DecodeHeader(guchar *Data, gint Bytes,
                 else if (depth <= 256)
                         depth = 8;
 
+               /* We check whether the HeaderSize (int) would overflow */
+                if (data_offset > INT_MAX - INFOHEADER_SIZE) {
+                       got_broken_header = TRUE;
+                       continue;
+               }
+
                entry = g_new0 (struct ico_direntry_data, 1);
                 entry->width = width ? width : 256;
                 entry->height = height ? height : 256;
@@ -326,16 +333,6 @@ static void DecodeHeader(guchar *Data, gint Bytes,
        for (l = State->entries; l != NULL; l = g_list_next (l)) {
                entry = l->data;
 
-               /* We check whether the HeaderSize (int) would overflow */
-               if (entry->DIBoffset > INT_MAX - INFOHEADER_SIZE)
-                 {
-                       g_set_error (error,
-                                    GDK_PIXBUF_ERROR,
-                                    GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                                    _("Invalid header in icon (%s)"), "dib offset");
-                       return;
-               }
-
                /* We know how many bytes are in the "header" part. */
                State->HeaderSize = entry->DIBoffset + INFOHEADER_SIZE;
 
@@ -381,9 +378,11 @@ static void DecodeHeader(guchar *Data, gint Bytes,
        /* No valid icon found, because all are compressed? */
        if (l == NULL) {
                g_set_error_literal (error,
-                                    GDK_PIXBUF_ERROR,
-                                    GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                                    _("Compressed icons are not supported"));
+                                    GDK_PIXBUF_ERROR,
+                                    GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                    got_broken_header ?
+                                       _("Invalid header in icon") :
+                                       _("Compressed icons are not supported"));
                return;
        }
 


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