Commit b4f8e1a38 for imagemagick.org

commit b4f8e1a387dd1d0a0af516071831a235f2fdf437
Author: Dirk Lemstra <dirk@lemstra.org>
Date:   Sun Jan 25 18:49:10 2026 +0100

    No longer allow mutations on the first image of the list (GHSA-fwqw-2x5x-w566)

diff --git a/coders/msl.c b/coders/msl.c
index 8e20d171f..5d86d14b1 100644
--- a/coders/msl.c
+++ b/coders/msl.c
@@ -381,7 +381,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Add noise image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || ((n < 1) || (msl_info->image[n] == (Image *) NULL)))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -457,7 +457,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Annotate image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -792,7 +792,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           MagickBooleanType
             stack;

-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -850,7 +850,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Adjusts an image's orientation
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -880,7 +880,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Blur image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -976,7 +976,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Border image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -1098,7 +1098,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Add noise image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -1163,7 +1163,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
             radius = 0.0,
             sigma = 1.0;

-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
         {
           ThrowMSLException(OptionError,"NoImagesDefined",
             (const char *) tag);
@@ -1238,7 +1238,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Chop image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -1345,7 +1345,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Color floodfill image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -1477,7 +1477,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Composite image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -1820,7 +1820,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Contrast image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -1874,7 +1874,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Crop image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -1976,7 +1976,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Cycle-colormap image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2030,7 +2030,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Despeckle image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2056,7 +2056,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         }
       if (LocaleCompare((const char *) tag,"display") == 0)
         {
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2084,7 +2084,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Annotate image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2447,7 +2447,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Edge image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2513,7 +2513,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Emboss image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2592,7 +2592,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Enhance image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2621,7 +2621,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Equalize image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2649,7 +2649,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
     {
       if (LocaleCompare((const char *) tag, "flatten") == 0)
       {
-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
         {
           ThrowMSLException(OptionError,"NoImagesDefined",
             (const char *) tag);
@@ -2680,7 +2680,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Flip image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2712,7 +2712,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Flop image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2747,7 +2747,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Frame image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2901,7 +2901,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Gamma image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -2996,7 +2996,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         }
       else if (LocaleCompare((const char *) tag,"get") == 0)
         {
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -3130,7 +3130,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Implode image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -3202,7 +3202,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         double
           levelBlack = 0, levelGamma = 1, levelWhite = QuantumRange;

-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
         {
           ThrowMSLException(OptionError,"NoImagesDefined",
             (const char *) tag);
@@ -3277,7 +3277,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Magnify image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -3315,7 +3315,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Map image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -3403,7 +3403,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
             Matte floodfill image.
           */
           opacity=0.0;
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -3535,7 +3535,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Median-filter image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -3603,7 +3603,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Minify image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -3637,7 +3637,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Modulate image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -3767,7 +3767,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Negate image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -3836,7 +3836,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Normalize image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -3894,7 +3894,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Oil-paint image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -3962,7 +3962,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Opaque image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -4072,7 +4072,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         }
         if (LocaleCompare((const char *) tag, "profile") == 0)
           {
-            if (msl_info->image[n] == (Image *) NULL)
+            if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
               {
                 ThrowMSLException(OptionError,"NoImagesDefined",
                   (const char *) tag);
@@ -4186,7 +4186,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Quantize image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -4665,7 +4665,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Raise image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -4803,7 +4803,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Reduce-noise image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -4871,7 +4871,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         x=msl_info->image[n]->page.x;
         y=msl_info->image[n]->page.y;

-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
         {
           ThrowMSLException(OptionError,"NoImagesDefined",
             (const char *) tag);
@@ -4997,7 +4997,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         x_resolution,
         y_resolution;

-      if (msl_info->image[n] == (Image *) NULL)
+      if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
         {
           ThrowMSLException(OptionError,"NoImagesDefined",
             (const char *) tag);
@@ -5099,7 +5099,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Resize image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -5194,7 +5194,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Roll image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -5273,7 +5273,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         height=msl_info->image[n]->rows;
         x = y = 0;

-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
         {
           ThrowMSLException(OptionError,"NoImagesDefined",
             (const char *) tag);
@@ -5355,7 +5355,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Rotate image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -5419,7 +5419,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         /* init the values */
         double  degrees = 0;

-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
         {
           ThrowMSLException(OptionError,"NoImagesDefined",
             (const char *) tag);
@@ -5485,7 +5485,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Sample image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -5562,7 +5562,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Scale image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -5642,7 +5642,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Segment image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -5726,7 +5726,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         }
       else if (LocaleCompare((const char *) tag, "set") == 0)
       {
-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
         {
           ThrowMSLException(OptionError,"NoImagesDefined",(const char *) tag);
           break;
@@ -5900,7 +5900,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Shade image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -5991,7 +5991,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Shear image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -6091,7 +6091,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
             radius = 0.0,
             sigma = 1.0;

-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
           {
             ThrowMSLException(OptionError,"NoImagesDefined",
               (const char *) tag);
@@ -6164,7 +6164,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         width = height = 0;
         x = y = 0;

-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
         {
           ThrowMSLException(OptionError,"NoImagesDefined",
             (const char *) tag);
@@ -6255,7 +6255,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Shear image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -6344,7 +6344,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Signature image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -6368,7 +6368,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Solarize image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -6430,7 +6430,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Spread image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -6495,7 +6495,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         Image *
           watermark = (Image*) NULL;

-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
           {
             ThrowMSLException(OptionError,"NoImagesDefined",
               (const char *) tag);
@@ -6563,7 +6563,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         Image *
           stereoImage = (Image*) NULL;

-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
           {
             ThrowMSLException(OptionError,"NoImagesDefined",(const char *) tag);
             break;
@@ -6630,7 +6630,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Strip image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -6660,7 +6660,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
             index,
             swap_index;

-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -6726,7 +6726,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Swirl image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -6790,7 +6790,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Sync image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -6823,7 +6823,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
           /*
             Texture image.
           */
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -6878,7 +6878,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
         /* init the values */
         double  threshold = 0;

-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
           {
             ThrowMSLException(OptionError,"NoImagesDefined",(const char *) tag);
             break;
@@ -6923,7 +6923,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
       }
       else if (LocaleCompare((const char *) tag, "transparent") == 0)
       {
-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
           {
             ThrowMSLException(OptionError,"NoImagesDefined",(const char *) tag);
             break;
@@ -6967,7 +6967,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
       }
       else if (LocaleCompare((const char *) tag, "trim") == 0)
       {
-        if (msl_info->image[n] == (Image *) NULL)
+        if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
           {
             ThrowMSLException(OptionError,"NoImagesDefined",(const char *) tag);
             break;
@@ -7002,7 +7002,7 @@ static void MSLStartElement(void *context,const xmlChar *tag,
     {
       if (LocaleCompare((const char *) tag,"write") == 0)
         {
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -7098,7 +7098,7 @@ static void MSLEndElement(void *context,const xmlChar *tag)
     {
       if (LocaleCompare((const char *) tag,"comment") == 0 )
         {
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);
@@ -7153,7 +7153,7 @@ static void MSLEndElement(void *context,const xmlChar *tag)
     {
       if (LocaleCompare((const char *) tag,"label") == 0 )
         {
-          if (msl_info->image[n] == (Image *) NULL)
+          if ((n < 1) || (msl_info->image[n] == (Image *) NULL))
             {
               ThrowMSLException(OptionError,"NoImagesDefined",
                 (const char *) tag);