Added extra checks for indexed mode images.
authorDirk Lemstra <dirk@git.imagemagick.org>
Thu, 1 Feb 2018 19:52:50 +0000 (20:52 +0100)
committerDirk Lemstra <dirk@git.imagemagick.org>
Thu, 1 Feb 2018 19:53:00 +0000 (20:53 +0100)
Credit to OSS-Fuzz

coders/psd.c

index d1680eb000585e68937a90f7d91efa947124eac2..e7afc208fec7d0d4e150d633f1230c96cc616d73 100644 (file)
@@ -2059,6 +2059,8 @@ static Image *ReadPSDImage(const ImageInfo *image_info,ExceptionInfo *exception)
       (psd_info.depth != 16) && (psd_info.depth != 32))
     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
   psd_info.mode=ReadBlobMSBShort(image);
+  if ((psd_info.mode == IndexedMode) && (psd_info.channels > 3))
+    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(CoderEvent,GetMagickModule(),
       "  Image is %.20g x %.20g with channels=%.20g, depth=%.20g, mode=%s",
@@ -2113,6 +2115,8 @@ static Image *ReadPSDImage(const ImageInfo *image_info,ExceptionInfo *exception)
     Read PSD raster colormap only present for indexed and duotone images.
   */
   length=ReadBlobMSBLong(image);
+  if ((psd_info.mode == IndexedMode) && (length < 3))
+    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
   if (length != 0)
     {
       if (image->debug != MagickFalse)