]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/image-png.c
Merge changes from CUPS 1.5.1-r9875.
[thirdparty/cups.git] / filter / image-png.c
index 3b4469bc98204552787ef59827829ed397c66835..81defbffa25fcb8aa3b5d2cf2121bddc5938af7c 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: image-png.c 5508 2006-05-11 11:41:16Z mike $"
+ * "$Id: image-png.c 7437 2008-04-09 03:16:10Z mike $"
  *
- *   PNG image routines for the Common UNIX Printing System (CUPS).
+ *   PNG image routines for CUPS.
  *
- *   Copyright 1993-2006 by Easy Software Products.
+ *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 1993-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  *   This file is subject to the Apple OS-Developed Software exception.
  *
@@ -120,7 +111,7 @@ _cupsImageReadPNG(
   if (width == 0 || width > CUPS_IMAGE_MAX_WIDTH ||
       height == 0 || height > CUPS_IMAGE_MAX_HEIGHT)
   {
-    fprintf(stderr, "ERROR: PNG image has invalid dimensions %ux%u!\n",
+    fprintf(stderr, "DEBUG: PNG image has invalid dimensions %ux%u!\n",
             (unsigned)width, (unsigned)height);
     fclose(fp);
     return (1);
@@ -137,7 +128,7 @@ _cupsImageReadPNG(
 
     if (img->xppi == 0 || img->yppi == 0)
     {
-      fprintf(stderr, "ERROR: PNG image has invalid resolution %dx%d PPI\n",
+      fprintf(stderr, "DEBUG: PNG image has invalid resolution %dx%d PPI\n",
               img->xppi, img->yppi);
 
       img->xppi = img->yppi = 128;
@@ -179,16 +170,56 @@ _cupsImageReadPNG(
     * Interlaced images must be loaded all at once...
     */
 
+    size_t bufsize;                    /* Size of buffer */
+
+
     if (color_type == PNG_COLOR_TYPE_GRAY ||
        color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
-      in = malloc(img->xsize * img->ysize);
+    {
+      bufsize = img->xsize * img->ysize;
+
+      if ((bufsize / img->xsize) != img->ysize)
+      {
+       fprintf(stderr, "DEBUG: PNG image dimensions (%ux%u) too large!\n",
+               (unsigned)width, (unsigned)height);
+       fclose(fp);
+       return (1);
+      }
+    }
     else
-      in = malloc(img->xsize * img->ysize * 3);
+    {
+      bufsize = img->xsize * img->ysize * 3;
+
+      if ((bufsize / (img->xsize * 3)) != img->ysize)
+      {
+       fprintf(stderr, "DEBUG: PNG image dimensions (%ux%u) too large!\n",
+               (unsigned)width, (unsigned)height);
+       fclose(fp);
+       return (1);
+      }
+    }
+
+    in = malloc(bufsize);
   }
 
   bpp = cupsImageGetDepth(img);
   out = malloc(img->xsize * bpp);
 
+  if (!in || !out)
+  {
+    fputs("DEBUG: Unable to allocate memory for PNG image!\n", stderr);
+
+    if (in)
+      free(in);
+
+    if (out)
+      free(out);
+
+    fclose(fp);
+
+    return (1);
+  }
+
  /*
   * Read the image, interlacing as needed...
   */
@@ -280,5 +311,5 @@ _cupsImageReadPNG(
 
 
 /*
- * End of "$Id: image-png.c 5508 2006-05-11 11:41:16Z mike $".
+ * End of "$Id: image-png.c 7437 2008-04-09 03:16:10Z mike $".
  */