[gdk-pixbuf] ico: Always set errors



commit 0cff83e985fba5350695c00ed1ac30fc31ec5960
Author: Hanno Boeck <hanno hboeck de>
Date:   Wed Jul 6 13:05:00 2016 +0000

    ico: Always set errors
    
    When the ico header turn out to be bad, always set an
    error when we fail. Otherwise, applications will get
    confused.
    
    This commit also adds an example image with a bad ico header.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768484

 gdk-pixbuf/io-ico.c                                |   14 ++++++++++++--
 tests/test-images/randomly-modified/bad-header.ico |  Bin 0 -> 6 bytes
 2 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/gdk-pixbuf/io-ico.c b/gdk-pixbuf/io-ico.c
index 86714af..82d3e4e 100644
--- a/gdk-pixbuf/io-ico.c
+++ b/gdk-pixbuf/io-ico.c
@@ -258,8 +258,13 @@ static void DecodeHeader(guchar *Data, gint Bytes,
                State->HeaderBuf = tmp;
                State->BytesInHeaderBuf = State->HeaderSize;
        }
-       if (Bytes < State->HeaderSize)
+       if (Bytes < State->HeaderSize) {
+               g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                     _("Not enough bytes for header"));
                return;
+       }
 
        /* Now iterate through the ICONDIRENTRY structures, and sort them by
         * which one we think is "best" (essentially the largest) */
@@ -399,8 +404,13 @@ static void DecodeHeader(guchar *Data, gint Bytes,
                State->HeaderBuf = tmp;
                State->BytesInHeaderBuf = State->HeaderSize;
        }
-       if (Bytes < State->HeaderSize)
+       if (Bytes < State->HeaderSize) {
+               g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                     _("Not enough bytes for header"));
                return;
+       }
 
        /* Negative heights mean top-down pixel-order */
        if (State->Header.height < 0) {
diff --git a/tests/test-images/randomly-modified/bad-header.ico 
b/tests/test-images/randomly-modified/bad-header.ico
new file mode 100644
index 0000000..ddf4515
Binary files /dev/null and b/tests/test-images/randomly-modified/bad-header.ico differ


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