[gimp/gimp-2-6] PCX: Avoid allocation overflows.



commit aaf0dfe5306f8a6bf66c927fa6c5148d9ce53c36
Author: Nils Philippsen <nils redhat com>
Date:   Wed Dec 2 15:12:17 2009 +0100

    PCX: Avoid allocation overflows.
    
    Multiplying gint values may overflow unless cast into a larger type.
    (cherry picked from commit a9671395f6573e90316a9d748588c5435216f6ce)

 plug-ins/common/file-pcx.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/plug-ins/common/file-pcx.c b/plug-ins/common/file-pcx.c
index 36a1def..a65fb0d 100644
--- a/plug-ins/common/file-pcx.c
+++ b/plug-ins/common/file-pcx.c
@@ -432,19 +432,19 @@ load_image (const gchar  *filename,
 
   if (pcx_header.planes == 1 && pcx_header.bpp == 1)
     {
-      dest = (guchar *) g_malloc (width * height);
+      dest = g_new (guchar, ((gsize) width) * height);
       load_1 (fd, width, height, dest, bytesperline);
       gimp_image_set_colormap (image, mono, 2);
     }
   else if (pcx_header.planes == 4 && pcx_header.bpp == 1)
     {
-      dest = (guchar *) g_malloc (width * height);
+      dest = g_new (guchar, ((gsize) width) * height);
       load_4 (fd, width, height, dest, bytesperline);
       gimp_image_set_colormap (image, pcx_header.colormap, 16);
     }
   else if (pcx_header.planes == 1 && pcx_header.bpp == 8)
     {
-      dest = (guchar *) g_malloc (width * height);
+      dest = g_new (guchar, ((gsize) width) * height);
       load_8 (fd, width, height, dest, bytesperline);
       fseek (fd, -768L, SEEK_END);
       fread (cmap, 768, 1, fd);
@@ -452,7 +452,7 @@ load_image (const gchar  *filename,
     }
   else if (pcx_header.planes == 3 && pcx_header.bpp == 8)
     {
-      dest = (guchar *) g_malloc (width * height * 3);
+      dest = g_new (guchar, ((gsize) width) * height * 3);
       load_24 (fd, width, height, dest, bytesperline);
     }
   else



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