[gimp/gimp-2-6] file-xwd: sanity check # of colors and map entries (CVE-2013-1978)
- From: Nils Philippsen <nphilipp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-6] file-xwd: sanity check # of colors and map entries (CVE-2013-1978)
- Date: Wed, 4 Dec 2013 10:03:26 +0000 (UTC)
commit 0e859d77a41331a35d2666f20265468bdf38c372
Author: Nils Philippsen <nils redhat com>
Date: Tue Nov 26 10:49:42 2013 +0100
file-xwd: sanity check # of colors and map entries (CVE-2013-1978)
The number of colors in an image shouldn't be higher than the number of
colormap entries. Additionally, consolidate post error cleanup in
load_image().
(cherry picked from commit f597355beffd9e483e11407d4c3b56f32db3634d)
Conflicts:
plug-ins/common/file-xwd.c
plug-ins/common/file-xwd.c | 51 ++++++++++++++++++++++++-------------------
1 files changed, 28 insertions(+), 23 deletions(-)
---
diff --git a/plug-ins/common/file-xwd.c b/plug-ins/common/file-xwd.c
index e7447a2..1ca3890 100644
--- a/plug-ins/common/file-xwd.c
+++ b/plug-ins/common/file-xwd.c
@@ -422,9 +422,9 @@ static gint32
load_image (const gchar *filename,
GError **error)
{
- FILE *ifp;
+ FILE *ifp = NULL;
gint depth, bpp;
- gint32 image_ID;
+ gint32 image_ID = -1;
L_XWDFILEHEADER xwdhdr;
L_XWDCOLOR *xwdcolmap = NULL;
@@ -434,7 +434,7 @@ load_image (const gchar *filename,
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
- return -1;
+ goto out;
}
read_xwd_header (ifp, &xwdhdr);
@@ -443,8 +443,7 @@ load_image (const gchar *filename,
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Could not read XWD header from '%s'"),
gimp_filename_to_utf8 (filename));
- fclose (ifp);
- return -1;
+ goto out;
}
#ifdef XWD_COL_WAIT_DEBUG
@@ -466,12 +465,18 @@ load_image (const gchar *filename,
g_message (_("'%s':\nIllegal number of colormap entries: %ld"),
gimp_filename_to_utf8 (filename),
(long)xwdhdr.l_colormap_entries);
- fclose (ifp);
- return -1;
+ goto out;
}
if (xwdhdr.l_colormap_entries > 0)
{
+ if (xwdhdr.l_colormap_entries < xwdhdr.l_ncolors)
+ {
+ g_message (_("'%s':\nNumber of colormap entries < number of colors"),
+ gimp_filename_to_utf8 (filename));
+ goto out;
+ }
+
xwdcolmap = g_new (L_XWDCOLOR, xwdhdr.l_colormap_entries);
read_xwd_cols (ifp, &xwdhdr, xwdcolmap);
@@ -491,9 +496,7 @@ load_image (const gchar *filename,
if (xwdhdr.l_file_version != 7)
{
g_message (_("Can't read color entries"));
- g_free (xwdcolmap);
- fclose (ifp);
- return (-1);
+ goto out;
}
}
@@ -501,8 +504,7 @@ load_image (const gchar *filename,
{
g_message (_("'%s':\nNo image width specified"),
gimp_filename_to_utf8 (filename));
- fclose (ifp);
- return (-1);
+ goto out;
}
if (xwdhdr.l_pixmap_width > GIMP_MAX_IMAGE_SIZE
@@ -510,24 +512,21 @@ load_image (const gchar *filename,
{
g_message (_("'%s':\nImage width is larger than GIMP can handle"),
gimp_filename_to_utf8 (filename));
- fclose (ifp);
- return (-1);
+ goto out;
}
if (xwdhdr.l_pixmap_height <= 0)
{
g_message (_("'%s':\nNo image height specified"),
gimp_filename_to_utf8 (filename));
- fclose (ifp);
- return (-1);
+ goto out;
}
if (xwdhdr.l_pixmap_height > GIMP_MAX_IMAGE_SIZE)
{
g_message (_("'%s':\nImage height is larger than GIMP can handle"),
gimp_filename_to_utf8 (filename));
- fclose (ifp);
- return (-1);
+ goto out;
}
gimp_progress_init_printf (_("Opening '%s'"),
@@ -575,11 +574,6 @@ load_image (const gchar *filename,
break;
}
- fclose (ifp);
-
- if (xwdcolmap)
- g_free (xwdcolmap);
-
if (image_ID == -1 && ! (error && *error))
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("XWD-file %s has format %d, depth %d and bits per pixel %d. "
@@ -587,6 +581,17 @@ load_image (const gchar *filename,
gimp_filename_to_utf8 (filename),
(gint) xwdhdr.l_pixmap_format, depth, bpp);
+out:
+ if (ifp)
+ {
+ fclose (ifp);
+ }
+
+ if (xwdcolmap)
+ {
+ g_free (xwdcolmap);
+ }
+
return image_ID;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]