]> granicus.if.org Git - imagemagick/blobdiff - coders/gray.c
...
[imagemagick] / coders / gray.c
index 5fdf79da36d582f8312b5f7ba19af808569a177f..48f3745c4c5330f83ebc0854d31704633c7790c4 100644 (file)
@@ -17,7 +17,7 @@
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -183,6 +183,7 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
   scene=0;
   count=0;
   length=0;
+  status=MagickTrue;
   do
   {
     /*
@@ -201,6 +202,8 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
         length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
         pixels=(const unsigned char *) ReadBlobStream(image,length,
           GetQuantumPixels(quantum_info),&count);
+        if (count != (ssize_t) length)
+          break;
       }
     for (y=0; y < (ssize_t) image->extract_info.height; y++)
     {
@@ -215,6 +218,7 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
 
       if (count != (ssize_t) length)
         {
+          status=MagickFalse;
           ThrowFileException(exception,CorruptImageError,
             "UnexpectedEndOfFile",image->filename);
           break;
@@ -233,8 +237,7 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
             image->columns,1,exception);
           q=QueueAuthenticPixels(image,0,y-image->extract_info.y,image->columns,
             1,exception);
-          if ((p == (const Quantum *) NULL) ||
-              (q == (Quantum *) NULL))
+          if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
             break;
           for (x=0; x < (ssize_t) image->columns; x++)
           {
@@ -254,6 +257,8 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
         }
       pixels=(const unsigned char *) ReadBlobStream(image,length,
         GetQuantumPixels(quantum_info),&count);
+      if (count != (ssize_t) length)
+        break;
     }
     SetQuantumImageType(image,quantum_type);
     /*
@@ -284,6 +289,8 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
   quantum_info=DestroyQuantumInfo(quantum_info);
   canvas_image=DestroyImage(canvas_image);
   (void) CloseBlob(image);
+  if (status == MagickFalse)
+    return(DestroyImageList(image));
   return(GetFirstImageInList(image));
 }
 \f