Added check to make sure the correct number of bytes could be read.
authorDirk Lemstra <dirk@git.imagemagick.org>
Thu, 11 May 2017 20:45:43 +0000 (22:45 +0200)
committerDirk Lemstra <dirk@git.imagemagick.org>
Thu, 11 May 2017 20:45:43 +0000 (22:45 +0200)
coders/psd.c

index 2bc0cccf81528fc87176ca1465384daa48a43afc..4799f9b4a9d464a0561c44b974f9b0b0581812e7 100644 (file)
@@ -1204,11 +1204,14 @@ static MagickBooleanType ReadPSDChannelZip(Image *image,const size_t channels,
       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
         image->filename);
     }
-
+  if (ReadBlob(image,compact_size,compact_pixels) != (ssize_t) compact_size)
+    {
+      compact_pixels=(unsigned char *) RelinquishMagickMemory(compact_pixels);
+      ThrowBinaryException(CorruptImageError,"UnexpectedEndOfFile",
+        image->filename);
+    }
   ResetMagickMemory(&stream,0,sizeof(stream));
   stream.data_type=Z_BINARY;
-  (void) ReadBlob(image,compact_size,compact_pixels);
-
   stream.next_in=(Bytef *)compact_pixels;
   stream.avail_in=(uInt) compact_size;
   stream.next_out=(Bytef *)pixels;