summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2017-07-13 22:17:49 +0200
committerBastien Nocera <hadess@hadess.net>2017-07-13 22:17:49 +0200
commitbe43c8f13751290c81f55336d4c08f4efc4fcd6e (patch)
tree82cd10054052fa81515c3d7f4b1af605330ca7ae
parentb92030b46ec0d4b7a38c0a9b79bcca5dd3aed5c6 (diff)
downloadgdk-pixbuf-be43c8f13751290c81f55336d4c08f4efc4fcd6e.tar.gz
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
-rw-r--r--gdk-pixbuf/io-ico.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/gdk-pixbuf/io-ico.c b/gdk-pixbuf/io-ico.c
index e5444640c..12f0a5880 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;
}