]> granicus.if.org Git - imagemagick/commitdiff
Only check the number of images limit if its a PCD overview
authorCristy <urban-warrior@imagemagick.org>
Sat, 31 Mar 2018 14:46:32 +0000 (10:46 -0400)
committerCristy <urban-warrior@imagemagick.org>
Sat, 31 Mar 2018 14:47:05 +0000 (10:47 -0400)
coders/pcd.c
coders/svg.c

index f361ac1f2f8a23e6695a1f7d4ebf623bcec064bd..a28cc6b856ef343104b4e36a26c7388486c6f239 100644 (file)
@@ -385,6 +385,7 @@ static MagickBooleanType IsPCD(const unsigned char *magick,const size_t length)
 %    o exception: return any errors or warnings in this structure.
 %
 */
+
 static Image *OverviewImage(const ImageInfo *image_info,Image *image,
   ExceptionInfo *exception)
 {
@@ -470,6 +471,19 @@ static void Upsample(const size_t width,const size_t height,
 
 static Image *ReadPCDImage(const ImageInfo *image_info,ExceptionInfo *exception)
 {
+#define ThrowPCDException(exception,message) \
+{ \
+  if (header != (unsigned char *) NULL) \
+    header=(unsigned char *) RelinquishMagickMemory(header); \
+  if (luma != (unsigned char *) NULL) \
+    luma=(unsigned char *) RelinquishMagickMemory(luma); \
+  if (chroma2 != (unsigned char *) NULL) \
+    chroma2=(unsigned char *) RelinquishMagickMemory(chroma2); \
+  if (chroma1 != (unsigned char *) NULL) \
+    chroma1=(unsigned char *) RelinquishMagickMemory(chroma1); \
+  ThrowReaderException((exception),(message)); \
+}
+
   Image
     *image;
 
@@ -537,25 +551,21 @@ static Image *ReadPCDImage(const ImageInfo *image_info,ExceptionInfo *exception)
   header=(unsigned char *) AcquireQuantumMemory(0x800,3UL*sizeof(*header));
   if (header == (unsigned char *) NULL)
     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+  chroma1=(unsigned char *) NULL;
+  chroma2=(unsigned char *) NULL;
+  luma=(unsigned char *) NULL;
   count=ReadBlob(image,3*0x800,header);
   if (count != (3*0x800))
-    {
-      header=(unsigned char *) RelinquishMagickMemory(header);
-      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
-    }
+    ThrowPCDException(CorruptImageError,"ImproperImageHeader");
   overview=LocaleNCompare((char *) header,"PCD_OPA",7) == 0;
   if ((LocaleNCompare((char *) header+0x800,"PCD",3) != 0) && (overview == 0))
-    {
-      header=(unsigned char *) RelinquishMagickMemory(header);
-      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
-    }
+    ThrowPCDException(CorruptImageError,"ImproperImageHeader");
   rotate=header[0x0e02] & 0x03;
-  number_images=(header[10] << 8) | header[11];
+  number_images=((header[10] << 8) | header[11]) & 0xffff;
   header=(unsigned char *) RelinquishMagickMemory(header);
-  if (number_images > 65535)
-    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
-  if (AcquireMagickResource(ListLengthResource,number_images) == MagickFalse)
-    ThrowReaderException(ResourceLimitError,"ListLengthExceedsLimit");
+  if ((overview != 0) &&
+      (AcquireMagickResource(ListLengthResource,number_images) == MagickFalse))
+    ThrowPCDException(ResourceLimitError,"ListLengthExceedsLimit");
   /*
     Determine resolution by scene specification.
   */
@@ -606,7 +616,7 @@ static Image *ReadPCDImage(const ImageInfo *image_info,ExceptionInfo *exception)
   */
   number_pixels=(MagickSizeType) image->columns*image->rows;
   if (number_pixels != (size_t) number_pixels)
-    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+    ThrowPCDException(ResourceLimitError,"MemoryAllocationFailed");
   chroma1=(unsigned char *) AcquireQuantumMemory(image->columns+1UL,image->rows*
     10*sizeof(*chroma1));
   chroma2=(unsigned char *) AcquireQuantumMemory(image->columns+1UL,image->rows*
@@ -615,15 +625,7 @@ static Image *ReadPCDImage(const ImageInfo *image_info,ExceptionInfo *exception)
     10*sizeof(*luma));
   if ((chroma1 == (unsigned char *) NULL) ||
       (chroma2 == (unsigned char *) NULL) || (luma == (unsigned char *) NULL))
-    {
-      if (chroma1 != (unsigned char *) NULL)
-        chroma1=(unsigned char *) RelinquishMagickMemory(chroma1);
-      if (chroma2 != (unsigned char *) NULL)
-        chroma2=(unsigned char *) RelinquishMagickMemory(chroma2);
-      if (luma != (unsigned char *) NULL)
-        luma=(unsigned char *) RelinquishMagickMemory(luma);
-      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
-    }
+    ThrowPCDException(ResourceLimitError,"MemoryAllocationFailed");
   (void) memset(chroma1,0,(image->columns+1UL)*image->rows*
     10*sizeof(*chroma1));
   (void) memset(chroma2,0,(image->columns+1UL)*image->rows*
@@ -643,12 +645,10 @@ static Image *ReadPCDImage(const ImageInfo *image_info,ExceptionInfo *exception)
       if (scene <= 1)
         offset=1;
   for (i=0; i < (ssize_t) (offset*0x800); i++)
-    (void) ReadBlobByte(image);
+    if (ReadBlobByte(image) == EOF)
+      ThrowPCDException(CorruptImageError,"UnexpectedEndOfFile");
   if (overview != 0)
     {
-      Image
-        *overview_image;
-
       MagickProgressMonitor
         progress_monitor;
 
@@ -683,6 +683,8 @@ static Image *ReadPCDImage(const ImageInfo *image_info,ExceptionInfo *exception)
           c1+=image->columns;
           count=ReadBlob(image,width >> 1,c2);
           c2+=image->columns;
+          if (EOFBlob(image) != MagickFalse)
+            ThrowPCDException(CorruptImageError,"UnexpectedEndOfFile");
         }
         Upsample(image->columns >> 1,image->rows >> 1,image->columns,chroma1);
         Upsample(image->columns >> 1,image->rows >> 1,image->columns,chroma2);
@@ -738,8 +740,7 @@ static Image *ReadPCDImage(const ImageInfo *image_info,ExceptionInfo *exception)
       chroma1=(unsigned char *) RelinquishMagickMemory(chroma1);
       luma=(unsigned char *) RelinquishMagickMemory(luma);
       image=GetFirstImageInList(image);
-      overview_image=OverviewImage(image_info,image,exception);
-      return(overview_image);
+      return(OverviewImage(image_info,image,exception));
     }
   /*
     Read interleaved image.
@@ -757,6 +758,8 @@ static Image *ReadPCDImage(const ImageInfo *image_info,ExceptionInfo *exception)
     c1+=image->columns;
     count=ReadBlob(image,width >> 1,c2);
     c2+=image->columns;
+    if (EOFBlob(image) != MagickFalse)
+      ThrowPCDException(CorruptImageError,"UnexpectedEndOfFile");
   }
   if (scene >= 4)
     {
index 2f5011576b3e7c12e73f2c647bdddf98e7200915..2546e47d3bc0daa86bba23cbbcba75b1b625cbb8 100644 (file)
@@ -788,6 +788,7 @@ static void SVGStartElement(void *context,const xmlChar *name,
 {
   char
     *color,
+    background[MagickPathExtent],
     id[MagickPathExtent],
     *next_token,
     token[MagickPathExtent],
@@ -829,6 +830,7 @@ static void SVGStartElement(void *context,const xmlChar *name,
   units=AcquireString("userSpaceOnUse");
   *id='\0';
   *token='\0';
+  *background='\0';
   value=(const char *) NULL;
   if ((LocaleCompare((char *) name,"image") == 0) ||
       (LocaleCompare((char *) name,"pattern") == 0) ||
@@ -1203,18 +1205,21 @@ static void SVGStartElement(void *context,const xmlChar *name,
         {
           if (LocaleCompare(keyword,"clip-path") == 0)
             {
-              (void) FormatLocaleFile(svg_info->file,"clip-path \"%s\"\n",value);
+              (void) FormatLocaleFile(svg_info->file,"clip-path \"%s\"\n",
+                value);
               break;
             }
           if (LocaleCompare(keyword,"clip-rule") == 0)
             {
-              (void) FormatLocaleFile(svg_info->file,"clip-rule \"%s\"\n",value);
+              (void) FormatLocaleFile(svg_info->file,"clip-rule \"%s\"\n",
+                value);
               break;
             }
           if (LocaleCompare(keyword,"clipPathUnits") == 0)
             {
               (void) CloneString(&units,value);
-              (void) FormatLocaleFile(svg_info->file,"clip-units \"%s\"\n",value);
+              (void) FormatLocaleFile(svg_info->file,"clip-units \"%s\"\n",
+                value);
               break;
             }
           if (LocaleCompare(keyword,"color") == 0)
@@ -1277,7 +1282,8 @@ static void SVGStartElement(void *context,const xmlChar *name,
             }
           if (LocaleCompare(keyword,"fill-rule") == 0)
             {
-              (void) FormatLocaleFile(svg_info->file,"fill-rule \"%s\"\n",value);
+              (void) FormatLocaleFile(svg_info->file,"fill-rule \"%s\"\n",
+                value);
               break;
             }
           if (LocaleCompare(keyword,"fill-opacity") == 0)
@@ -1300,7 +1306,8 @@ static void SVGStartElement(void *context,const xmlChar *name,
             }
           if (LocaleCompare(keyword,"font-style") == 0)
             {
-              (void) FormatLocaleFile(svg_info->file,"font-style \"%s\"\n",value);
+              (void) FormatLocaleFile(svg_info->file,"font-style \"%s\"\n",
+                value);
               break;
             }
           if (LocaleCompare(keyword,"font-size") == 0)
@@ -1616,7 +1623,8 @@ static void SVGStartElement(void *context,const xmlChar *name,
             {
               if (LocaleCompare(value,"currentColor") == 0)
                 {
-                  (void) FormatLocaleFile(svg_info->file,"stroke \"%s\"\n",color);
+                  (void) FormatLocaleFile(svg_info->file,"stroke \"%s\"\n",
+                    color);
                   break;
                 }
               (void) FormatLocaleFile(svg_info->file,"stroke \"%s\"\n",value);
@@ -1654,8 +1662,8 @@ static void SVGStartElement(void *context,const xmlChar *name,
             }
           if (LocaleCompare(keyword,"stroke-miterlimit") == 0)
             {
-              (void) FormatLocaleFile(svg_info->file,"stroke-miterlimit \"%s\"\n",
-                value);
+              (void) FormatLocaleFile(svg_info->file,
+                "stroke-miterlimit \"%s\"\n",value);
               break;
             }
           if (LocaleCompare(keyword,"stroke-opacity") == 0)
@@ -1682,6 +1690,18 @@ static void SVGStartElement(void *context,const xmlChar *name,
                   "    %s: %s",keyword,value);
                 switch (*keyword)
                 {
+                  case 'B':
+                  case 'b':
+                  {
+                    if (LocaleCompare((const char *) name,"background") == 0)
+                      {
+                        if (LocaleCompare((const char *) name,"svg") == 0)
+                          (void) CopyMagickString(background,value,
+                            MagickPathExtent);
+                        break;
+                      }
+                    break;
+                  }
                   case 'C':
                   case 'c':
                   {
@@ -1726,8 +1746,8 @@ static void SVGStartElement(void *context,const xmlChar *name,
                           (void) FormatLocaleFile(svg_info->file,
                             "fill '#000000'\n");
                         else
-                          (void) FormatLocaleFile(svg_info->file,"fill \"%s\"\n",
-                            value);
+                          (void) FormatLocaleFile(svg_info->file,
+                            "fill \"%s\"\n",value);
                         break;
                       }
                     if (LocaleCompare(keyword,"fillcolor") == 0)
@@ -2251,6 +2271,15 @@ static void SVGStartElement(void *context,const xmlChar *name,
             0.0;
           (void) FormatLocaleFile(svg_info->file,"affine %g 0 0 %g %g %g\n",
             sx,sy,tx,ty);
+          if (*background != '\0')
+            {
+              (void) FormatLocaleFile(svg_info->file,"push graphic-context\n");
+              (void) FormatLocaleFile(svg_info->file,"fill %s\n",background);
+              (void) FormatLocaleFile(svg_info->file,
+                "rectangle 0,0 %g,%g\n",svg_info->view_box.width,
+                svg_info->view_box.height);
+              (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n");
+            }
         }
     }
   (void) LogMagickEvent(CoderEvent,GetMagickModule(),"  )");