]> granicus.if.org Git - imagemagick/blobdiff - coders/pcl.c
(no commit message)
[imagemagick] / coders / pcl.c
index 08272439735038f7fb4031aa879d1c9b5cb47e32..0fc6ca823f7ee49700c280a4f6dd7e2464e9f453 100644 (file)
@@ -106,10 +106,10 @@ static MagickBooleanType IsPCL(const unsigned char *magick,const size_t length)
 {
   if (length < 4)
     return(MagickFalse);
-  if (memcmp(magick,"\033E\033",3) == 0)
-    return(MagickTrue);
   if (memcmp(magick,"\033E\033&",4) == 0)
     return(MagickFalse);
+  if (memcmp(magick,"\033E\033",3) == 0)
+    return(MagickTrue);
   return(MagickFalse);
 }
 \f
@@ -505,8 +505,9 @@ static size_t PCLDeltaCompressImage(const size_t length,
         }
       j++;
     }
-    for ( ; x < (ssize_t) length; x++)
+    while (x < (ssize_t) length)
     {
+      x++;
       if (*pixels == *previous_pixels)
         break;
       i++;
@@ -801,9 +802,10 @@ static MagickBooleanType WritePCLImage(const ImageInfo *image_info,Image *image)
       (void) WriteBlobString(image,"\033*r1A");  /* start raster graphics */
     (void) WriteBlobString(image,"\033*b0Y");  /* set y offset */
     length=(image->columns*bits_per_pixel+7)/8;
-    pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
+    pixels=(unsigned char *) AcquireQuantumMemory(length+1,sizeof(*pixels));
     if (pixels == (unsigned char *) NULL)
       ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+    (void) ResetMagickMemory(pixels,0,(length+1)*sizeof(*pixels));
     compress_pixels=(unsigned char *) NULL;
     previous_pixels=(unsigned char *) NULL;
     switch (image->compression)
@@ -823,20 +825,24 @@ static MagickBooleanType WritePCLImage(const ImageInfo *image_info,Image *image)
             pixels=(unsigned char *) RelinquishMagickMemory(pixels);
             ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
           }
+        (void) ResetMagickMemory(compress_pixels,0,(length+256)*
+          sizeof(*compress_pixels));
         (void) FormatMagickString(buffer,MaxTextExtent,"\033*b2M");
         (void) WriteBlobString(image,buffer);
         break;
       }
       default:
       {
-        compress_pixels=(unsigned char *) AcquireQuantumMemory(length+
-          (length >> 3),sizeof(*compress_pixels));
+        compress_pixels=(unsigned char *) AcquireQuantumMemory(length+32,
+          sizeof(*compress_pixels));
         if (compress_pixels == (unsigned char *) NULL)
           {
             pixels=(unsigned char *) RelinquishMagickMemory(pixels);
             ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
           }
-        previous_pixels=(unsigned char *) AcquireQuantumMemory(length,
+        (void) ResetMagickMemory(compress_pixels,0,(length+32)*
+          sizeof(*compress_pixels));
+        previous_pixels=(unsigned char *) AcquireQuantumMemory(length+1,
           sizeof(*previous_pixels));
         if (previous_pixels == (unsigned char *) NULL)
           {
@@ -845,6 +851,8 @@ static MagickBooleanType WritePCLImage(const ImageInfo *image_info,Image *image)
             pixels=(unsigned char *) RelinquishMagickMemory(pixels);
             ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
           }
+        (void) ResetMagickMemory(previous_pixels,0,(length+1)*
+          sizeof(*previous_pixels));
         (void) FormatMagickString(buffer,MaxTextExtent,"\033*b3M");
         (void) WriteBlobString(image,buffer);
         break;