Commit eeb580da3 for imagemagick.org

commit eeb580da36b73dc1c45383cee432084d5227ebbf
Author: Cristy <urban-warrior@imagemagick.org>
Date:   Fri Dec 4 11:11:53 2026 -0500

    StrictReadInlineImage() now throws an exception for NULL content

diff --git a/MagickCore/constitute-private.h b/MagickCore/constitute-private.h
index 7869fb797..2a4d57ecd 100644
--- a/MagickCore/constitute-private.h
+++ b/MagickCore/constitute-private.h
@@ -18,10 +18,8 @@
 #ifndef MAGICKCORE_CONSTITUTE_PRIVATE_H
 #define MAGICKCORE_CONSTITUTE_PRIVATE_H

-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
+#include <assert.h>
+#include <errno.h>
 #include "MagickCore/constitute.h"
 #include "MagickCore/exception.h"
 #include "MagickCore/log.h"
@@ -29,19 +27,33 @@ extern "C" {
 #include "MagickCore/magick-private.h"
 #include "MagickCore/utility.h"

+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+#if !defined(MagickMaxCoderDepth)
+#  define MagickMaxCoderDepth  128
+#endif
+
 extern MagickExport Image
   *ReadImageWithoutPostProcessing(const ImageInfo *,ExceptionInfo *);

+/*
+  Count one level of coder nesting against image_info.  The counter is bumped
+  even when the check fails, so a caller that ignores the result cannot
+  recurse past the limit.
+*/
 static inline MagickBooleanType CheckCoderDepth(ImageInfo *image_info,
   ExceptionInfo *exception)
 {
-#define MagickMaxCoderDepth  128
-
+  assert(image_info != (ImageInfo *) NULL);
+  assert(image_info->signature == MagickCoreSignature);
+  assert(exception != (ExceptionInfo *) NULL);
   if (image_info->coder_depth++ >= MagickMaxCoderDepth)
     {
-      errno=EPERM;
       (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
         "ImageNestedTooDeeply","`%s'",image_info->filename);
+      errno=EPERM;  /* set last: the throw above may clobber errno */
       return(MagickFalse);
     }
   return(MagickTrue);
@@ -53,21 +65,31 @@ static inline Image *StrictReadImage(ImageInfo *image_info,
   char
     magic[MagickPathExtent];

+  assert(image_info != (ImageInfo *) NULL);
+  assert(image_info->signature == MagickCoreSignature);
+  assert(exception != (ExceptionInfo *) NULL);
   if (CheckCoderDepth(image_info,exception) == MagickFalse)
     return((Image *) NULL);
+  *magic='\0';
   (void) GetPathComponent(image_info->filename,MagickPath,magic);
   if (*magic != '\0')
     {
-      const MagickInfo *magick_info = GetMagickInfo(magic,exception);
-      if ((magick_info != (const MagickInfo *) NULL) &&
-          (GetMagickExplicitAllowed(magick_info) != MagickFalse))
-          return(ReadImage(image_info,exception));
-      else
+      const MagickInfo
+        *magick_info;
+
+      /*
+        Explicit coder prefix (e.g. "fmt:name"): only permitted for coders
+        that opt in.
+      */
+      magick_info=GetMagickInfo(magic,exception);
+      if ((magick_info == (const MagickInfo *) NULL) ||
+          (GetMagickExplicitAllowed(magick_info) == MagickFalse))
         {
           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
             "ExplicitCoderNotAllowed","`%s'",image_info->filename);
           return((Image *) NULL);
         }
+      return(ReadImage(image_info,exception));
     }
   if (IsPathAccessible(image_info->filename) == MagickFalse)
     {
@@ -81,8 +103,17 @@ static inline Image *StrictReadImage(ImageInfo *image_info,
 static inline Image *StrictReadInlineImage(ImageInfo *image_info,
   const char *content,ExceptionInfo *exception)
 {
+  assert(image_info != (ImageInfo *) NULL);
+  assert(image_info->signature == MagickCoreSignature);
+  assert(exception != (ExceptionInfo *) NULL);
   if (CheckCoderDepth(image_info,exception) == MagickFalse)
     return((Image *) NULL);
+  if (content == (const char *) NULL)
+    {
+      (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+        "NullInlineImageContent","`%s'",image_info->filename);
+      return((Image *) NULL);
+    }
   return(ReadInlineImage(image_info,content,exception));
 }