Index: GraphicsMagick-1.2.5/coders/cmyk.c
===================================================================
--- GraphicsMagick-1.2.5.orig/coders/cmyk.c	2018-02-09 11:33:39.029037428 +0100
+++ GraphicsMagick-1.2.5/coders/cmyk.c	2018-02-09 11:51:27.847027720 +0100
@@ -1,5 +1,5 @@
 /*
-% Copyright (C) 2003, 2004 GraphicsMagick Group
+% Copyright (C) 2003 - 2017 GraphicsMagick Group
 % Copyright (C) 2002 ImageMagick Studio
 % Copyright 1991-1999 E. I. du Pont de Nemours and Company
 %
@@ -92,6 +82,11 @@ static size_t MagickArraySize(const size
 %
 %
 */
+#define ThrowCMYKReaderException(code_,reason_,image_) \
+{ \
+  MagickFreeMemory(scanline);                 \
+  ThrowReaderException(code_,reason_,image_); \
+}
 static Image *ReadCMYKImage(const ImageInfo *image_info,
   ExceptionInfo *exception)
 {
@@ -102,17 +97,18 @@ static Image *ReadCMYKImage(const ImageI
     y;
 
   register long
-    i,
-    x;
+    i;
 
   register PixelPacket
     *q;
 
   size_t
-    count;
+    count,
+    tile_packets,
+    x;
 
   unsigned char
-    *scanline;
+    *scanline = (unsigned char *) NULL;
 
   unsigned int
     status;
@@ -121,13 +117,41 @@ static Image *ReadCMYKImage(const ImageI
     packet_size,
     quantum_size;
 
+  ImportPixelAreaOptions
+    import_options;
+
   assert(image_info != (const ImageInfo *) NULL);
   assert(image_info->signature == MagickSignature);
   assert(exception != (ExceptionInfo *) NULL);
   assert(exception->signature == MagickSignature);
   image=AllocateImage(image_info);
+  if (image->logging)
+    (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                          "Size %lux%lu", image->columns, image->rows);
   if ((image->columns == 0) || (image->rows == 0))
     ThrowReaderException(OptionError,MustSpecifyImageSize,image);
+
+  if (image->logging)
+    (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                          "Tile %lux%lu%+ld%+ld, Offset %lu",
+                          image->tile_info.width,image->tile_info.height,
+                          image->tile_info.x,image->tile_info.y,
+                          image->offset);
+  /*
+    There is the option to either require that the tile be within the
+    image bounds or to return only the portion of the tile which is
+    within the image bounds (returned image is smaller than requested
+    tile size).  For the moment we choose the former.
+  */
+  if ((image->tile_info.width > image->columns) ||
+      (image->tile_info.x < 0) ||
+      (image->tile_info.width+image->tile_info.x > image->columns) ||
+      (image->tile_info.height > image->rows) ||
+      (image->tile_info.y < 0) ||
+      (image->tile_info.height+image->tile_info.y > image->rows)
+      )
+    ThrowReaderException(CorruptImageError,ImproperImageHeader,image);
+
   if (image_info->interlace != PartitionInterlace)
     {
       /*
@@ -135,7 +159,7 @@ static Image *ReadCMYKImage(const ImageI
       */
       status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
       if (status == False)
-        ThrowReaderException(FileOpenError,UnableToOpenFile,image);
+        ThrowCMYKReaderException(FileOpenError,UnableToOpenFile,image);
       for (i=0; i < image->offset; i++)
         {
           if (EOF == ReadBlobByte(image))
@@ -143,16 +167,17 @@ static Image *ReadCMYKImage(const ImageI
                            image->filename);
         }
     }
+
   /*
     Allocate memory for a scanline.
   */
 
   if (image->depth <= 8)
-    quantum_size=8;
+    quantum_size=8U;
   else if (image->depth <= 16)
-    quantum_size=16;
+    quantum_size=16U;
   else
-    quantum_size=32;
+    quantum_size=32U;
 
   packet_size=(quantum_size*4)/8;
   if (LocaleCompare(image_info->magick,"CMYKA") == 0)
@@ -160,10 +185,22 @@ static Image *ReadCMYKImage(const ImageI
       image->matte=True;
       packet_size=(quantum_size*5)/8;
     }
-  scanline=MagickAllocateMemory(unsigned char *,
-    packet_size*image->tile_info.width);
+  scanline=MagickAllocateArray(unsigned char *,
+                               packet_size,image->columns);
   if (scanline == (unsigned char *) NULL)
-    ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);
+    ThrowCMYKReaderException(ResourceLimitError,MemoryAllocationFailed,image);
+  tile_packets=(size_t) packet_size*image->tile_info.width;
+  x=(size_t) (packet_size*image->tile_info.x);
+ /*
+    Initialize import options.
+  */
+  ImportPixelAreaOptionsInit(&import_options);
+  if (image_info->endian != UndefinedEndian)
+    import_options.endian=image_info->endian;
+
+ /*
+    Support starting at intermediate image frame.
+  */
   if (image_info->subrange != 0)
     while (image->scene < image_info->subimage)
     {
@@ -172,9 +209,9 @@ static Image *ReadCMYKImage(const ImageI
       */
       image->scene++;
       for (y=0; y < (long) image->rows; y++)
-        (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+        if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+          break;
     }
-  x=(long) (packet_size*image->tile_info.x);
   do
   {
     /*
@@ -193,18 +230,22 @@ static Image *ReadCMYKImage(const ImageI
           No interlacing:  CMYKCMYKCMYKCMYKCMYKCMYK...
         */
         for (y=0; y < image->tile_info.y; y++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         for (y=0; y < (long) image->rows; y++)
         {
           if ((y > 0) || (image->previous == (Image *) NULL))
-            (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+            if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+              break;
           q=SetImagePixels(image,0,y,image->columns,1);
           if (q == (PixelPacket *) NULL)
             break;
           if (!image->matte)
-            (void) ImportImagePixelArea(image,CMYKQuantum,quantum_size,scanline+x,0,0);
+            (void) ImportImagePixelArea(image,CMYKQuantum,quantum_size,scanline+x,
+                                        &import_options,0);
           else
-            (void) ImportImagePixelArea(image,CMYKAQuantum,quantum_size,scanline+x,0,0);
+            (void) ImportImagePixelArea(image,CMYKAQuantum,quantum_size,scanline+x,
+                                        &import_options,0);
           if (!SyncImagePixels(image))
             break;
           if (image->previous == (Image *) NULL)
@@ -214,7 +255,8 @@ static Image *ReadCMYKImage(const ImageI
         }
         count=image->tile_info.height-image->rows-image->tile_info.y;
         for (i=0; i < (long) count; i++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         break;
       }
       case LineInterlace:
@@ -224,26 +266,36 @@ static Image *ReadCMYKImage(const ImageI
         */
         packet_size=(quantum_size)/8;
         for (y=0; y < image->tile_info.y; y++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         for (y=0; y < (long) image->rows; y++)
         {
           if ((y > 0) || (image->previous == (Image *) NULL))
-            (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+            if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+              break;
           q=SetImagePixels(image,0,y,image->columns,1);
           if (q == (PixelPacket *) NULL)
             break;
-          (void) ImportImagePixelArea(image,CyanQuantum,quantum_size,scanline+x,0,0);
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
-          (void) ImportImagePixelArea(image,MagentaQuantum,quantum_size,scanline+x,0,0);
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
-          (void) ImportImagePixelArea(image,YellowQuantum,quantum_size,scanline+x,0,0);
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
-          (void) ImportImagePixelArea(image,BlackQuantum,quantum_size,scanline+x,0,0);
+          (void) ImportImagePixelArea(image,CyanQuantum,quantum_size,scanline+x,
+                                      &import_options,0);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
+          (void) ImportImagePixelArea(image,MagentaQuantum,quantum_size,scanline+x,
+                                      &import_options,0);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
+          (void) ImportImagePixelArea(image,YellowQuantum,quantum_size,scanline+x,
+                                      &import_options,0);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
+          (void) ImportImagePixelArea(image,BlackQuantum,quantum_size,scanline+x,
+                                      &import_options,0);
           if (image->matte)
             {
-              (void) ReadBlob(image,packet_size*image->tile_info.width,
-                scanline);
-              (void) ImportImagePixelArea(image,AlphaQuantum,quantum_size,scanline+x,0,0);
+              if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+                break;
+              (void) ImportImagePixelArea(image,AlphaQuantum,quantum_size,scanline+x,
+                                          &import_options,0);
             }
           if (!SyncImagePixels(image))
             break;
@@ -254,7 +306,8 @@ static Image *ReadCMYKImage(const ImageI
         }
         count=image->tile_info.height-image->rows-image->tile_info.y;
         for (i=0; i < (long) count; i++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         break;
       }
       case PlaneInterlace:
@@ -271,21 +324,24 @@ static Image *ReadCMYKImage(const ImageI
             AppendImageFormat("C",image->filename);
             status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
             if (status == False)
-              ThrowReaderException(FileOpenError,UnableToOpenFile,image);
+              ThrowCMYKReaderException(FileOpenError,UnableToOpenFile,image);
           }
         packet_size=(quantum_size)/8;
         for (y=0; y < image->tile_info.y; y++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         i=0;
         span=image->rows*(image->matte ? 5 : 4);
         for (y=0; y < (long) image->rows; y++)
         {
           if ((y > 0) || (image->previous == (Image *) NULL))
-            (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+            if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+              break;
           q=SetImagePixels(image,0,y,image->columns,1);
           if (q == (PixelPacket *) NULL)
             break;
-          (void) ImportImagePixelArea(image,CyanQuantum,quantum_size,scanline+x,0,0);
+          (void) ImportImagePixelArea(image,CyanQuantum,quantum_size,scanline+x,
+                                      &import_options,0);
           if (!SyncImagePixels(image))
             break;
           if (image->previous == (Image *) NULL)
@@ -296,24 +352,28 @@ static Image *ReadCMYKImage(const ImageI
         }
         count=image->tile_info.height-image->rows-image->tile_info.y;
         for (i=0; i < (long) count; i++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         if (image_info->interlace == PartitionInterlace)
           {
             CloseBlob(image);
             AppendImageFormat("M",image->filename);
             status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
             if (status == False)
-              ThrowReaderException(FileOpenError,UnableToOpenFile,image);
+              ThrowCMYKReaderException(FileOpenError,UnableToOpenFile,image);
           }
         for (y=0; y < image->tile_info.y; y++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         for (y=0; y < (long) image->rows; y++)
         {
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
           q=GetImagePixels(image,0,y,image->columns,1);
           if (q == (PixelPacket *) NULL)
             break;
-          (void) ImportImagePixelArea(image,MagentaQuantum,quantum_size,scanline+x,0,0);
+          (void) ImportImagePixelArea(image,MagentaQuantum,quantum_size,scanline+x,
+                                      &import_options,0);
           if (!SyncImagePixels(image))
             break;
           if (image->previous == (Image *) NULL)
@@ -324,24 +384,28 @@ static Image *ReadCMYKImage(const ImageI
         }
         count=image->tile_info.height-image->rows-image->tile_info.y;
         for (i=0; i < (long) count; i++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         if (image_info->interlace == PartitionInterlace)
           {
             CloseBlob(image);
             AppendImageFormat("Y",image->filename);
             status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
             if (status == False)
-              ThrowReaderException(FileOpenError,UnableToOpenFile,image);
+              ThrowCMYKReaderException(FileOpenError,UnableToOpenFile,image);
           }
         for (y=0; y < image->tile_info.y; y++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         for (y=0; y < (long) image->rows; y++)
         {
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
           q=GetImagePixels(image,0,y,image->columns,1);
           if (q == (PixelPacket *) NULL)
             break;
-          (void) ImportImagePixelArea(image,YellowQuantum,quantum_size,scanline+x,0,0);
+          (void) ImportImagePixelArea(image,YellowQuantum,quantum_size,scanline+x,
+                                      &import_options,0);
           if (!SyncImagePixels(image))
             break;
           if (image->previous == (Image *) NULL)
@@ -352,24 +416,28 @@ static Image *ReadCMYKImage(const ImageI
         }
         count=image->tile_info.height-image->rows-image->tile_info.y;
         for (i=0; i < (long) count; i++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         if (image_info->interlace == PartitionInterlace)
           {
             CloseBlob(image);
             AppendImageFormat("K",image->filename);
             status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
             if (status == False)
-              ThrowReaderException(FileOpenError,UnableToOpenFile,image);
+              ThrowCMYKReaderException(FileOpenError,UnableToOpenFile,image);
           }
         for (y=0; y < image->tile_info.y; y++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         for (y=0; y < (long) image->rows; y++)
         {
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
           q=GetImagePixels(image,0,y,image->columns,1);
           if (q == (PixelPacket *) NULL)
             break;
-          (void) ImportImagePixelArea(image,BlackQuantum,quantum_size,scanline+x,0,0);
+          (void) ImportImagePixelArea(image,BlackQuantum,quantum_size,scanline+x,
+                                      &import_options,0);
           if (!SyncImagePixels(image))
             break;
           if (image->previous == (Image *) NULL)
@@ -380,7 +448,8 @@ static Image *ReadCMYKImage(const ImageI
         }
         count=image->tile_info.height-image->rows-image->tile_info.y;
         for (i=0; i < (long) count; i++)
-          (void) ReadBlob(image,packet_size*image->tile_info.width,scanline);
+          if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+            break;
         if (image->matte)
           {
             /*
@@ -392,19 +461,20 @@ static Image *ReadCMYKImage(const ImageI
                 AppendImageFormat("A",image->filename);
                 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
                 if (status == False)
-                  ThrowReaderException(FileOpenError,UnableToOpenFile,image);
+                  ThrowCMYKReaderException(FileOpenError,UnableToOpenFile,image);
               }
             for (y=0; y < image->tile_info.y; y++)
-              (void) ReadBlob(image,packet_size*image->tile_info.width,
-                scanline);
+              if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+                break;
             for (y=0; y < (long) image->rows; y++)
             {
-              (void) ReadBlob(image,packet_size*image->tile_info.width,
-                scanline);
+              if (ReadBlob(image,tile_packets,scanline)  != tile_packets)
+                break;
               q=GetImagePixels(image,0,y,image->columns,1);
               if (q == (PixelPacket *) NULL)
                 break;
-              (void) ImportImagePixelArea(image,AlphaQuantum,quantum_size,scanline+x,0,0);
+              (void) ImportImagePixelArea(image,AlphaQuantum,quantum_size,scanline+x,
+                                          &import_options,0);
               if (!SyncImagePixels(image))
                 break;
               if (image->previous == (Image *) NULL)
@@ -415,8 +485,8 @@ static Image *ReadCMYKImage(const ImageI
             }
             count=image->tile_info.height-image->rows-image->tile_info.y;
             for (i=0; i < (long) count; i++)
-              (void) ReadBlob(image,packet_size*image->tile_info.width,
-                scanline);
+              if (ReadBlob(image,tile_packets,scanline) != tile_packets)
+                break;
           }
         if (image_info->interlace == PartitionInterlace)
           (void) strlcpy(image->filename,image_info->filename,MaxTextExtent);
@@ -437,8 +507,8 @@ static Image *ReadCMYKImage(const ImageI
         break;
     if (image_info->interlace == PartitionInterlace)
       break;
-    count=ReadBlob(image,packet_size*image->tile_info.width,scanline);
-    if (count != 0)
+    count=ReadBlob(image,tile_packets,scanline);
+    if (count == tile_packets)
       {
         /*
           Allocate next image structure.
@@ -450,8 +520,7 @@ static Image *ReadCMYKImage(const ImageI
             return((Image *) NULL);
           }
         image=SyncNextImageInList(image);
-        status=MagickMonitor(LoadImagesText,TellBlob(image),GetBlobSize(image),
-          exception);
+        status=MagickMonitor(LoadImagesText,TellBlob(image),GetBlobSize(image),exception);;
         if (status == False)
           break;
       }
@@ -582,10 +650,17 @@ static unsigned int WriteCMYKImage(const
     scene,
     status;
 
+  ExportPixelAreaOptions
+    export_options;
+
+  ExportPixelAreaInfo
+    export_info;
+
   assert(image_info != (const ImageInfo *) NULL);
   assert(image_info->signature == MagickSignature);
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
+
   if (image_info->interlace != PartitionInterlace)
     {
       /*
@@ -629,6 +704,15 @@ static unsigned int WriteCMYKImage(const
       ThrowWriterException(ResourceLimitError,MemoryAllocationFailed,image);
 
     /*
+      Initialize export options.
+    */
+    ExportPixelAreaOptionsInit(&export_options);
+    if (image->endian != UndefinedEndian)
+      export_options.endian=image->endian;
+    else if (image_info->endian != UndefinedEndian)
+      export_options.endian=image_info->endian;
+
+    /*
       Convert MIFF to CMYK raster pixels.
     */
     (void) TransformColorspace(image,CMYKColorspace);
@@ -644,21 +728,17 @@ static unsigned int WriteCMYKImage(const
         /*
           No interlacing:  CMYKCMYKCMYKCMYKCMYKCMYK...
         */
+        const QuantumType quantum_type =
+          (LocaleCompare(image_info->magick,"CMYKA") == 0) ? CMYKAQuantum :
+          CMYKQuantum;
         for (y=0; y < (long) image->rows; y++)
         {
           p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
           if (p == (const PixelPacket *) NULL)
             break;
-          if (LocaleCompare(image_info->magick,"CMYKA") != 0)
-            {
-              (void) ExportImagePixelArea(image,CMYKQuantum,quantum_size,pixels,0,0);
-              (void) WriteBlob(image,packet_size*image->columns,pixels);
-            }
-          else
-            {
-              (void) ExportImagePixelArea(image,CMYKAQuantum,quantum_size,pixels,0,0);
-              (void) WriteBlob(image,packet_size*image->columns,pixels);
-            }
+          (void) ExportImagePixelArea(image,quantum_type,quantum_size,pixels,
+                                      &export_options,&export_info);
+          (void) WriteBlob(image,export_info.bytes_exported,pixels);
           if (image->previous == (Image *) NULL)
             if (QuantumTick(y,image->rows))
               if (!MagickMonitor(SaveImageText,y,image->rows,&image->exception))
@@ -676,18 +756,23 @@ static unsigned int WriteCMYKImage(const
           p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
           if (p == (const PixelPacket *) NULL)
             break;
-          (void) ExportImagePixelArea(image,CyanQuantum,quantum_size,pixels,0,0);
-          (void) WriteBlob(image,image->columns,pixels);
-          (void) ExportImagePixelArea(image,MagentaQuantum,quantum_size,pixels,0,0);
-          (void) WriteBlob(image,image->columns,pixels);
-          (void) ExportImagePixelArea(image,YellowQuantum,quantum_size,pixels,0,0);
-          (void) WriteBlob(image,image->columns,pixels);
-          (void) ExportImagePixelArea(image,BlackQuantum,quantum_size,pixels,0,0);
-          (void) WriteBlob(image,image->columns,pixels);
+          (void) ExportImagePixelArea(image,CyanQuantum,quantum_size,pixels,
+                                      &export_options,&export_info);
+          (void) WriteBlob(image,export_info.bytes_exported,pixels);
+          (void) ExportImagePixelArea(image,MagentaQuantum,quantum_size,pixels,
+                                      &export_options,&export_info);
+          (void) WriteBlob(image,export_info.bytes_exported,pixels);
+          (void) ExportImagePixelArea(image,YellowQuantum,quantum_size,pixels,
+                                      &export_options,&export_info);
+          (void) WriteBlob(image,export_info.bytes_exported,pixels);
+          (void) ExportImagePixelArea(image,BlackQuantum,quantum_size,pixels,
+                                      &export_options,&export_info);
+          (void) WriteBlob(image,export_info.bytes_exported,pixels);
           if (LocaleCompare(image_info->magick,"CMYKA") == 0)
             {
-              (void) ExportImagePixelArea(image,AlphaQuantum,quantum_size,pixels,0,0);
-              (void) WriteBlob(image,image->columns,pixels);
+              (void) ExportImagePixelArea(image,AlphaQuantum,quantum_size,pixels,
+                                          &export_options,&export_info);
+              (void) WriteBlob(image,export_info.bytes_exported,pixels);
             }
           if (QuantumTick(y,image->rows))
             if (!MagickMonitor(SaveImageText,y,image->rows,&image->exception))
@@ -714,8 +799,9 @@ static unsigned int WriteCMYKImage(const
           p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
           if (p == (const PixelPacket *) NULL)
             break;
-          (void) ExportImagePixelArea(image,CyanQuantum,quantum_size,pixels,0,0);
-          (void) WriteBlob(image,image->columns,pixels);
+          (void) ExportImagePixelArea(image,CyanQuantum,quantum_size,pixels,
+                                      &export_options,&export_info);
+          (void) WriteBlob(image,export_info.bytes_exported,pixels);
         }
         if (image_info->interlace == PartitionInterlace)
           {
@@ -733,8 +819,9 @@ static unsigned int WriteCMYKImage(const
           p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
           if (p == (const PixelPacket *) NULL)
             break;
-          (void) ExportImagePixelArea(image,MagentaQuantum,quantum_size,pixels,0,0);
-          (void) WriteBlob(image,image->columns,pixels);
+          (void) ExportImagePixelArea(image,MagentaQuantum,quantum_size,pixels,
+                                      &export_options,&export_info);
+          (void) WriteBlob(image,export_info.bytes_exported,pixels);
         }
         if (image_info->interlace == PartitionInterlace)
           {
@@ -752,8 +839,9 @@ static unsigned int WriteCMYKImage(const
           p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
           if (p == (const PixelPacket *) NULL)
             break;
-          (void) ExportImagePixelArea(image,YellowQuantum,quantum_size,pixels,0,0);
-          (void) WriteBlob(image,image->columns,pixels);
+          (void) ExportImagePixelArea(image,YellowQuantum,quantum_size,pixels,
+                                      &export_options,&export_info);
+          (void) WriteBlob(image,export_info.bytes_exported,pixels);
         }
         if (image_info->interlace == PartitionInterlace)
           {
@@ -771,8 +859,9 @@ static unsigned int WriteCMYKImage(const
           p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
           if (p == (const PixelPacket *) NULL)
             break;
-          (void) ExportImagePixelArea(image,BlackQuantum,quantum_size,pixels,0,0);
-          (void) WriteBlob(image,image->columns,pixels);
+          (void) ExportImagePixelArea(image,BlackQuantum,quantum_size,pixels,
+                                      &export_options,&export_info);
+          (void) WriteBlob(image,export_info.bytes_exported,pixels);
         }
         if (LocaleCompare(image_info->magick,"CMYKA") == 0)
           {
@@ -793,22 +882,21 @@ static unsigned int WriteCMYKImage(const
                 &image->exception);
               if (p == (const PixelPacket *) NULL)
                 break;
-              (void) ExportImagePixelArea(image,AlphaQuantum,quantum_size,pixels,0,0);
-              (void) WriteBlob(image,image->columns,pixels);
+              (void) ExportImagePixelArea(image,AlphaQuantum,quantum_size,pixels,
+                                          &export_options,&export_info);
+              (void) WriteBlob(image,export_info.bytes_exported,pixels);
             }
           }
         if (image_info->interlace == PartitionInterlace)
           (void) strlcpy(image->filename,image_info->filename,MaxTextExtent);
-        if (!MagickMonitor(SaveImageText,400,400,&image->exception))
-          break;
+        (void) MagickMonitor(SaveImageText,400,400,&image->exception);
         break;
       }
     }
     if (image->next == (Image *) NULL)
       break;
     image=SyncNextImageInList(image);
-    status=MagickMonitor(SaveImagesText,scene++,GetImageListLength(image),
-      &image->exception);
+    status=MagickMonitor(SaveImagesText,scene++,GetImageListLength(image),&image->exception);
     if (status == False)
       break;
   } while (image_info->adjoin);
