Commit 3815bd047 for imagemagick.org

commit 3815bd047f435f23b70535f939d2fe67610b2359
Author: Cristy <urban-warrior@imagemagick.org>
Date:   Fri Dec 4 18:44:31 2026 -0500

    WriteMATTEImage now fails, and writes nothing, when the pixel cache cannot be read

diff --git a/coders/matte.c b/coders/matte.c
index 647acf173..01fa5db75 100644
--- a/coders/matte.c
+++ b/coders/matte.c
@@ -177,6 +177,14 @@ static MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
   ssize_t
     y;

+  assert(image_info != (const ImageInfo *) NULL);
+  assert(image_info->signature == MagickCoreSignature);
+  assert(image != (Image *) NULL);
+  assert(image->signature == MagickCoreSignature);
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickCoreSignature);
+  if (IsEventLogging() != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if ((image->alpha_trait & BlendPixelTrait) == 0)
     ThrowWriterException(CoderError,"ImageDoesNotHaveAnAlphaChannel");
   matte_image=CloneImage(image,0,0,MagickTrue,exception);
@@ -187,12 +195,16 @@ static MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
   /*
     Convert image to matte pixels.
   */
+  status=MagickTrue;
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     p=GetVirtualPixels(image,0,y,image->columns,1,exception);
     q=QueueAuthenticPixels(matte_image,0,y,matte_image->columns,1,exception);
     if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
-      break;
+      {
+        status=MagickFalse;
+        break;
+      }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
       SetPixelRed(matte_image,GetPixelAlpha(image,p),q);
@@ -203,12 +215,23 @@ static MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
       q+=(ptrdiff_t) GetPixelChannels(matte_image);
     }
     if (SyncAuthenticPixels(matte_image,exception) == MagickFalse)
-      break;
+      {
+        status=MagickFalse;
+        break;
+      }
     status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
       image->rows);
     if (status == MagickFalse)
       break;
   }
+  if (status == MagickFalse)
+    {
+      /*
+        Do not emit a partially converted matte image.
+      */
+      matte_image=DestroyImage(matte_image);
+      return(MagickFalse);
+    }
   write_info=CloneImageInfo(image_info);
   if ((*write_info->magick == '\0') ||
       (LocaleCompare(write_info->magick,"MATTE") == 0))