Commit d183d8cfa for imagemagick.org

commit d183d8cfaa7ce52900d0f3a16300abcdb1150663
Author: Cristy <urban-warrior@imagemagick.org>
Date:   Sat Dec 5 07:07:55 2026 -0500

    https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-5gg9-p566-q4cg

diff --git a/coders/miff.c b/coders/miff.c
index 2baf6a6c7..838542b40 100644
--- a/coders/miff.c
+++ b/coders/miff.c
@@ -520,7 +520,8 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
     colors=0;
     image->depth=8UL;
     image->compression=NoCompression;
-    while ((isgraph((int) ((unsigned char) c)) != 0) && (c != (int) ':'))
+    while ((c != EOF) && (isgraph((int) ((unsigned char) c)) != 0) &&
+           (c != (int) ':'))
     {
       char
         *p;
@@ -539,7 +540,11 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
           {
             c=ReadBlobByte(image);
             if (c == (int) '\\')
-              c=ReadBlobByte(image);
+              {
+                c=ReadBlobByte(image);
+                if (c == EOF)
+                  break;
+              }
             else
               if ((c == EOF) || (c == (int) '}'))
                 break;
@@ -1115,10 +1120,24 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
           }
         else
           c=ReadBlobByte(image);
-      while (isspace((int) ((unsigned char) c)) != 0)
+      while ((c != EOF) && (isspace((int) ((unsigned char) c)) != 0))
         c=ReadBlobByte(image);
     }
     options=DestroyString(options);
+    if (c == EOF)
+      {
+        /*
+          Header ended before the ':' terminator.
+        */
+        if (profiles != (LinkedListInfo *) NULL)
+          profiles=DestroyLinkedList(profiles,RelinquishMagickMemory);
+        if (image->previous == (Image *) NULL)
+          ThrowMIFFException(CorruptImageError,"UnexpectedEndOfFile");
+        DeleteImageFromList(&image);
+        (void) ThrowMagickException(exception,GetMagickModule(),
+          CorruptImageError,"UnexpectedEndOfFile","`%s'",image->filename);
+        break;
+      }
     (void) ReadBlobByte(image);
     /*
       Verify that required image information is defined.
diff --git a/coders/mpc.c b/coders/mpc.c
index 2d15a5dac..56ad941c7 100644
--- a/coders/mpc.c
+++ b/coders/mpc.c
@@ -234,7 +234,8 @@ static Image *ReadMPCImage(const ImageInfo *image_info,ExceptionInfo *exception)
     nonce=DestroyStringInfo(nonce);
     image->depth=8;
     image->compression=NoCompression;
-    while ((isgraph((int) ((unsigned char) c)) != 0) && (c != (int) ':'))
+    while ((c != EOF) && (isgraph((int) ((unsigned char) c)) != 0) &&
+           (c != (int) ':'))
     {
       char
         *p;
@@ -303,7 +304,7 @@ static Image *ReadMPCImage(const ImageInfo *image_info,ExceptionInfo *exception)
             } while (c != EOF);
             *p='\0';
             p=options;
-            while (isspace((int) ((unsigned char) c)) != 0)
+            while ((c != EOF) && (isspace((int) ((unsigned char) c)) != 0))
               c=ReadBlobByte(image);
             if (c == (int) '=')
               {
@@ -804,10 +805,19 @@ static Image *ReadMPCImage(const ImageInfo *image_info,ExceptionInfo *exception)
           }
         else
           c=ReadBlobByte(image);
-      while (isspace((int) ((unsigned char) c)) != 0)
+      while ((c != EOF) && (isspace((int) ((unsigned char) c)) != 0))
         c=ReadBlobByte(image);
     }
     options=DestroyString(options);
+    if (c == EOF)
+      {
+        /*
+          Header ended before the ':' terminator.
+        */
+        if (profiles != (LinkedListInfo *) NULL)
+          profiles=DestroyLinkedList(profiles,RelinquishMagickMemory);
+        ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
+      }
     (void) ReadBlobByte(image);
     /*
       Verify that required image information is defined.