GraphicsMagick: 2 new changesets

GraphicsMagick Commits <[email protected]> Thu, 16 May 2024 08:25:32 -0500
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.2792.1715865946.1586.graphicsmagick-commit@lists.sourceforge.net>
changeset 9587ea1511cb in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=9587ea1511cb
summary: coders/tiff.c "profile_lenght" has been incorrectly decreased. It should stay constant.

changeset 1f4005a1b5f0 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=1f4005a1b5f0
summary: Remove C++ comments from C code and change whitespace to use only spaces.

diffstat:

 ChangeLog          |   8 ++++-
 coders/bmp.c       |  54 ++++++++++++++++----------------
 coders/jxl.c       |   4 +-
 coders/mat.c       |   2 +-
 coders/tga.c       |  34 ++++++++++---------
 coders/tiff.c      |  87 ++++++++++++++++++++++++++-------------------------
 coders/topol.c     |  22 ++++++------
 coders/wpg.c       |  90 +++++++++++++++++++++++++++---------------------------
 www/ChangeLog.html |  10 +++++-
 9 files changed, 164 insertions(+), 147 deletions(-)

diffs (truncated from 892 to 500 lines):

diff -r 320af918e5b3 -r 1f4005a1b5f0 ChangeLog
--- a/ChangeLog	Wed May 15 18:24:58 2024 -0500
+++ b/ChangeLog	Thu May 16 08:25:01 2024 -0500
@@ -1,6 +1,12 @@
+2024-05-16  Bob Friesenhahn  <[email protected]>
+
+	* coders/{bmp.c,jxl.c,mat.c,tga.c,tiff.c,topol.c,wpg.c}: Remove
+	C++ comments from C code and change whitespace to use only spaces.
+
 2024-05-16  Fojtik Jaroslav  <[email protected]>
-	* coders/tiff.c: TIFFTAG_INKNAMES should have a first parameter of 
+	* coders/tiff.c: TIFFTAG_INKNAMES should have a first parameter of
 	the type uint16_t.
+	profile_lenght has been incorrectly decreased.
 
 2024-05-15  Bob Friesenhahn  <[email protected]>
 
diff -r 320af918e5b3 -r 1f4005a1b5f0 coders/bmp.c
--- a/coders/bmp.c	Wed May 15 18:24:58 2024 -0500
+++ b/coders/bmp.c	Thu May 16 08:25:01 2024 -0500
@@ -92,11 +92,11 @@
 #endif /* !defined(MSWINDOWS) || defined(__MINGW32__) */
 
 #if (QuantumDepth == 8)
-  #define MS_VAL16_TO_QUANTUM(_value)	((_value>=8192)?255:(_value>>5))
+  #define MS_VAL16_TO_QUANTUM(_value)   ((_value>=8192)?255:(_value>>5))
 #elif (QuantumDepth == 16)
-  #define MS_VAL16_TO_QUANTUM(_value)	((_value>=8192)?65535:(_value*8))
+  #define MS_VAL16_TO_QUANTUM(_value)   ((_value>=8192)?65535:(_value*8))
 #elif (QuantumDepth == 32)
-  #define MS_VAL16_TO_QUANTUM(_value)	((_value>=8192)?4294443007:(_value*524288))
+  #define MS_VAL16_TO_QUANTUM(_value)   ((_value>=8192)?4294443007:(_value*524288))
 #else
 # error Unsupported quantum depth.
 #endif
@@ -534,10 +534,10 @@
 {
   switch(BiCompression)
   {
-    case BI_RGB:  return "BI_RGB";	/* uncompressed */
-    case BI_RLE4: return "BI_RLE4";	/* 4 bit RLE */
-    case BI_RLE8: return "BI_RLE8";	/* 8 bit RLE */
-    case BI_BITFIELDS: 
+    case BI_RGB:  return "BI_RGB";      /* uncompressed */
+    case BI_RLE4: return "BI_RLE4";     /* 4 bit RLE */
+    case BI_RLE8: return "BI_RLE8";     /* 8 bit RLE */
+    case BI_BITFIELDS:
                   if(BiSize==64) return "OS/2 Huffman 1D";
                             else return "BI_BITFIELDS";
     case BI_JPEG: if(BiSize==64) return "OS/2 RLE-24";
@@ -905,7 +905,7 @@
             }
 
           if(bmp_info.size==64)
-            {				/* OS22XBITMAPHEADER */
+            {                           /* OS22XBITMAPHEADER */
               magick_uint16_t  Units;            /* Type of units used to measure resolution */
               magick_uint16_t  Reserved;         /* Pad structure to 4-byte boundary */
               magick_uint16_t  Recording;        /* Recording algorithm */
@@ -1154,7 +1154,7 @@
           if(bmp_info.size==40)
             {
               if(bmp_info.ba_offset==0) bmp_info.ba_offset=52;
-              if(bmp_info.ba_offset<52)		/* check for gap size >=12*/
+              if(bmp_info.ba_offset<52)         /* check for gap size >=12*/
                  ThrowBMPReaderException(CorruptImageError,CorruptImage,image);
               bmp_info.red_mask=ReadBlobLSBLong(image);
               bmp_info.green_mask=ReadBlobLSBLong(image);
@@ -1166,7 +1166,7 @@
           if(bmp_info.size==40)
             {
               if(bmp_info.ba_offset==0) bmp_info.ba_offset=56;
-              if(bmp_info.ba_offset<56)		/* check for gap size >=16*/
+              if(bmp_info.ba_offset<56)         /* check for gap size >=16*/
                  ThrowBMPReaderException(CorruptImageError,CorruptImage,image);
               bmp_info.red_mask=ReadBlobLSBLong(image);
               bmp_info.green_mask=ReadBlobLSBLong(image);
@@ -1211,7 +1211,7 @@
             if (exception->severity >= ErrorException)
                 ThrowBMPReaderException(CoderError,JPEGCompressionNotSupported,image)
           }
-          goto ExitLoop;	/* I need to break a loop. Other BMPs in a chain are ignored. */
+          goto ExitLoop;        /* I need to break a loop. Other BMPs in a chain are ignored. */
 
         case BI_PNG:
           offset = start_position + 14 + bmp_info.size;
@@ -1230,7 +1230,7 @@
             if (exception->severity >= ErrorException)
                 ThrowBMPReaderException(CoderError,PNGCompressionNotSupported,image)
           }
-          goto ExitLoop;	/* I need to break a loop. Other BMPs in a chain are ignored. */
+          goto ExitLoop;        /* I need to break a loop. Other BMPs in a chain are ignored. */
 
         default:
           ThrowBMPReaderException(CorruptImageError,UnrecognizedImageCompression,image)
@@ -1455,22 +1455,22 @@
       /*
         Convert BMP raster image to pixel packets.
       */
-      /*
-        if (bmp_info.compression == BI_RGB)
+#if 0
+      if (bmp_info.compression == BI_RGB)
         {
-        bmp_info.alpha_mask=(image->matte ? 0xff000000U : 0U);
-        bmp_info.red_mask=0x00ff0000U;
-        bmp_info.green_mask=0x0000ff00U;
-        bmp_info.blue_mask=0x000000ffU;
-        if (bmp_info.bits_per_pixel == 16)
-        {
-        // RGB555.   JFO: Please consider whether this is correct ?? I guess RGB 565!
-        bmp_info.red_mask=0x00007c00U;
-        bmp_info.green_mask=0x000003e0U;
-        bmp_info.blue_mask=0x0000001fU;
+          bmp_info.alpha_mask=(image->matte ? 0xff000000U : 0U);
+          bmp_info.red_mask=0x00ff0000U;
+          bmp_info.green_mask=0x0000ff00U;
+          bmp_info.blue_mask=0x000000ffU;
+          if (bmp_info.bits_per_pixel == 16)
+            {
+              /* RGB555.   JFO: Please consider whether this is correct ?? I guess RGB 565! */
+              bmp_info.red_mask=0x00007c00U;
+              bmp_info.green_mask=0x000003e0U;
+              bmp_info.blue_mask=0x0000001fU;
+            }
         }
-        }
-      */
+#endif
       if ((bmp_info.bits_per_pixel == 16) || (bmp_info.bits_per_pixel == 32))
         {
           register magick_uint32_t
@@ -1834,7 +1834,7 @@
                     q->green = MS_VAL16_TO_QUANTUM(val_16);
                     LD_UINT16_LSB(val_16,p);
                     q->red = MS_VAL16_TO_QUANTUM(val_16);
-                    p+=2;		/* TODO: add alpha*/
+                    p+=2;               /* TODO: add alpha*/
                     q++;
                   }
                 if(!SyncImagePixels(image))
diff -r 320af918e5b3 -r 1f4005a1b5f0 coders/jxl.c
--- a/coders/jxl.c	Wed May 15 18:24:58 2024 -0500
+++ b/coders/jxl.c	Thu May 16 08:25:01 2024 -0500
@@ -919,8 +919,8 @@
                                                 &import_options,&import_area_info))
                     != MagickPass)
                   break;
-                // Promote linear image to sRGB (2.4 gamma).
-                // We could also set image->gamma and return the original image.
+                /* Promote linear image to sRGB (2.4 gamma).
+                   We could also set image->gamma and return the original image. */
 #if 1
                 if (isLinear)
                   {
diff -r 320af918e5b3 -r 1f4005a1b5f0 coders/mat.c
--- a/coders/mat.c	Wed May 15 18:24:58 2024 -0500
+++ b/coders/mat.c	Thu May 16 08:25:01 2024 -0500
@@ -236,7 +236,7 @@
       f = (*p / MaxVal) * (Quantum)(MaxRGB - q->red);
       if (MAGICK_ISNAN(f))
         f=0.0;
-      /*if(f<0) f=0;    //Only for Assert, should be commented out */
+      /*if(f<0) f=0;    // Only for Assert, should be commented out */
       if (f + q->red < MaxRGB)
         q->red += (int)f;
       else
diff -r 320af918e5b3 -r 1f4005a1b5f0 coders/tga.c
--- a/coders/tga.c	Wed May 15 18:24:58 2024 -0500
+++ b/coders/tga.c	Thu May 16 08:25:01 2024 -0500
@@ -357,7 +357,7 @@
     base,
     flag,
     offset,
-//    real,
+    /*    real, */
     skip;
 
   unsigned int
@@ -689,16 +689,18 @@
       base=0;
       flag=0;
       skip=MagickFalse;
-//    real=0;
+      /*    real=0; */
       index=0;
       runlength=0;
       offset=0;
       pixel.opacity=OpaqueOpacity;
       for (y=0; y < (long) image->rows; y++)
         {
-//          real=offset;
-//          if (((tga_info.attributes & 0x20) >> 5) == 0)
-//            real=image->rows-real-1;
+          /*
+            real=offset;
+            if (((tga_info.attributes & 0x20) >> 5) == 0)
+            real=image->rows-real-1;
+          */
           q=SetImagePixels(image,0,(long)offset,image->columns,1);
           if (q == (PixelPacket *) NULL)
             break;
@@ -731,7 +733,7 @@
                 switch (tga_info.bits_per_pixel)
                   {
                   case 1:
-                    if ((x&7) == 0)     // Read byte every 8th bit.
+                    if ((x&7) == 0)     /* Read byte every 8th bit. */
                       index = ReadBlobByte(image);
                     else
                       index <<= 1;
@@ -836,11 +838,11 @@
               *q++=pixel;
             }
           switch((unsigned char) (tga_info.attributes & 0xc0) >> 6)
-            {				/* http://www.paulbourke.net/dataformats/tga/ */
-            case 3:			/* 11 = reserved. - process without interleaving. */
-            case 0: offset++; break;	/* 00 = non-interleaved. */
-            case 1: offset+=2;break;	/* 01 = two-way (even/odd) interleaving. */
-            case 2: offset+=4;break;	/* 10 = four way interleaving. */
+            {                           /* http://www.paulbourke.net/dataformats/tga/ */
+            case 3:                     /* 11 = reserved. - process without interleaving. */
+            case 0: offset++; break;    /* 00 = non-interleaved. */
+            case 1: offset+=2;break;    /* 01 = two-way (even/odd) interleaving. */
+            case 2: offset+=4;break;    /* 10 = four way interleaving. */
             }
           if (offset >= image->rows)
             {
@@ -1124,7 +1126,7 @@
       if (((write_grayscale == MagickFalse) &&
            (image->storage_class == PseudoClass) &&
            (image->colors > 256)) || (image->matte == MagickTrue))
-        {	/* TODO: We should decide whether opacity could be packed into palette or
+        {       /* TODO: We should decide whether opacity could be packed into palette or
                 the full alpha channel is needed. */
           /* (void) SyncImage(image); */
           image->storage_class=DirectClass;
@@ -1197,10 +1199,10 @@
       switch(image->orientation)
       {
         case UndefinedOrientation:
-        case BottomLeftOrientation:  break;				/* 01 Bottom left */
-        case BottomRightOrientation: tga_info.attributes|=0x10; break;	/* 01 Bottom right */
-        case TopLeftOrientation:     tga_info.attributes|=0x20; break;	/* 10 Top left */
-        case TopRightOrientation:    tga_info.attributes|=0x30; break;	/* 11 TopRight */
+        case BottomLeftOrientation:  break;                             /* 01 Bottom left */
+        case BottomRightOrientation: tga_info.attributes|=0x10; break;  /* 01 Bottom right */
+        case TopLeftOrientation:     tga_info.attributes|=0x20; break;  /* 10 Top left */
+        case TopRightOrientation:    tga_info.attributes|=0x30; break;  /* 11 TopRight */
         default: if(image->logging)
                      (void)LogMagickEvent(CoderEvent,GetMagickModule(),
                                 "Warning: Orientation %d is not supported, use -auto-orient switch.\n", (int)image->orientation);
diff -r 320af918e5b3 -r 1f4005a1b5f0 coders/tiff.c
--- a/coders/tiff.c	Wed May 15 18:24:58 2024 -0500
+++ b/coders/tiff.c	Thu May 16 08:25:01 2024 -0500
@@ -4406,9 +4406,9 @@
 #if EXPERIMENTAL_EXIF_TAGS
 #if TIFFLIB_VERSION >= 20120922
 
-#define FLAG_EXIF	1
-#define FLAG_GPS	2
-#define FLAG_BASE	4
+#define FLAG_EXIF       1
+#define FLAG_GPS        2
+#define FLAG_BASE       4
 
 
 /*
@@ -4466,14 +4466,14 @@
 {
 magick_uint32_t i = StrSize;
 
-  if(Tag==TIFFTAG_INKNAMES)		/* Variant of call is tag dependent, too bad. */
+  if(Tag==TIFFTAG_INKNAMES)             /* Variant of call is tag dependent, too bad. */
   {
     if(StrSize>0xFFFF) return 0;
     /* TIFFTAG_INKNAMES needs only uint16_t https://libtiff.gitlab.io/libtiff/functions/TIFFSetField.html#c.TIFFSetField */
     return TIFFSetField(tiff, Tag, (magick_uint16_t)StrSize, String);
   }
 
-	/* Look for zero terminator. */
+        /* Look for zero terminator. */
   while(i>0)
   {
     i--;
@@ -4484,7 +4484,7 @@
   }
 
   if(StrSize>0)
-  {	/* Try to duplicate unterminated string. */
+  {     /* Try to duplicate unterminated string. */
     char *StringDup = MagickAllocateResourceLimitedMemory(char *, StrSize+1);
     if(StringDup!=NULL)
     {
@@ -4499,7 +4499,8 @@
 }
 
 
-static int AddIFDExifFields(TIFF *tiff, const unsigned char *profile_data, const unsigned char *IFD_data, size_t profile_length, MagickBool logging, magick_uint16_t Flags)
+static int AddIFDExifFields(TIFF *tiff, const unsigned char * const profile_data, const unsigned char *IFD_data, const size_t profile_length,
+                MagickBool logging, magick_uint16_t Flags)
 {
 magick_uint32_t(*LD_UINT32)(const unsigned char *Mem);
 magick_uint16_t(*LD_UINT16)(const unsigned char *Mem);
@@ -4525,7 +4526,7 @@
   {
     if(profile_length < (size_t)(IFD_data-profile_data)+2) return 0;
     EntryNum = LD_UINT16(IFD_data);
-    profile_length-=2;
+    /* profile_length-=2; */
     if(profile_length < (size_t)(IFD_data-profile_data)+(EntryNum*12)) return 0;
     IFD_data+=2;
 
@@ -4545,10 +4546,10 @@
          Tag==TIFFTAG_IMAGELENGTH || Tag==TIFFTAG_IMAGEWIDTH ||
          Tag==TIFFTAG_SAMPLESPERPIXEL || Tag==TIFFTAG_BITSPERSAMPLE || Tag==TIFFTAG_SAMPLEFORMAT ||
          Tag==TIFFTAG_STRIPOFFSETS || Tag==TIFFTAG_ROWSPERSTRIP || Tag==TIFFTAG_STRIPBYTECOUNTS ||
-         Tag==TIFFTAG_ORIENTATION ||		/* Orientation is handled different way. */
+         Tag==TIFFTAG_ORIENTATION ||            /* Orientation is handled different way. */
          Tag==TIFFTAG_XRESOLUTION || Tag==TIFFTAG_YRESOLUTION)
       {
-          goto NextItem;	/* Banned TIFF tags that cannot be copyed from EXIF. */
+          goto NextItem;        /* Banned TIFF tags that cannot be copyed from EXIF. */
       }
 
       if(Tag == TIFFTAG_EXIFIFD)
@@ -4566,7 +4567,7 @@
         goto NextItem;
       }
 
-      if(fip!=NULL && (Flags & FLAG_BASE)!=0)		/* libtiff doesn't understand these */
+      if(fip!=NULL && (Flags & FLAG_BASE)!=0)           /* libtiff doesn't understand these */
       {
         const TIFFDataType FDT = TIFFFieldDataType(fip);
         const int WriteCount = TIFFFieldWriteCount(fip);
@@ -4574,15 +4575,15 @@
         {
           case TIFF_ASCII:
                          if(FDT!=TIFF_ASCII)
-                             break;		/* Incompatible recipe.*/
+                             break;             /* Incompatible recipe.*/
                          if(Long2<=4)
                          {
-                           if(CheckAndStoreStr(tiff, Tag, (const char *) IFD_data+8, Long2))	/* The short string is inside Value. */
+                           if(CheckAndStoreStr(tiff, Tag, (const char *) IFD_data+8, Long2))    /* The short string is inside Value. */
                              FieldCount++;
                          }
                          else
                          {
-                           if(Value+Long2>=profile_length-1) break;		/* String outside EXIF boundary. */
+                           if(Value+Long2>=profile_length-1) break;             /* String outside EXIF boundary. */
                            if(CheckAndStoreStr(tiff, Tag, (const char *) profile_data+Value, Long2))
                              FieldCount++;
                          }
@@ -4593,9 +4594,9 @@
                          {
                            magick_uint16_t *Array;
                            magick_uint32_t i;
-                           if(FDT!=Field) break;			/* Incompatible array type, might be converted in future. */
+                           if(FDT!=Field) break;                        /* Incompatible array type, might be converted in future. */
                            if(WriteCount!=TIFF_VARIABLE && WriteCount!=TIFF_VARIABLE2)
-                               break;					/* Fixed size arrays not handled. */
+                               break;                                   /* Fixed size arrays not handled. */
                            if(Value+2*Long2>=profile_length-1) break;
                            if(Long2==0) break;
                            Array = MagickAllocateResourceLimitedMemory(magick_uint16_t *, 2*Long2);
@@ -4604,11 +4605,11 @@
                                Array[i] = LD_UINT16(profile_data+Value+2*i);
                            if(WriteCount==TIFF_VARIABLE)
                            {
-                             if(TIFFSetField(tiff, Tag, (int)Long2, Array))	/* Argument 3 type int, argument 4 uint16_t*. */
+                             if(TIFFSetField(tiff, Tag, (int)Long2, Array))     /* Argument 3 type int, argument 4 uint16_t*. */
                                FieldCount++;
                            } else if(WriteCount==TIFF_VARIABLE2)
                            {
-                             if(TIFFSetField(tiff, Tag, Long2, Array))		/* Argument 3 type uint32_t, argument 4 uint16_t*.. */
+                             if(TIFFSetField(tiff, Tag, Long2, Array))          /* Argument 3 type uint32_t, argument 4 uint16_t*.. */
                                FieldCount++;
                            }
                            MagickFreeResourceLimitedMemory(Array);
@@ -4621,9 +4622,9 @@
                          {
                            magick_uint32_t *Array;
                            magick_uint32_t i;
-                           if(FDT!=Field) break;			/* Incompatible array type, might be converted in future. */
+                           if(FDT!=Field) break;                        /* Incompatible array type, might be converted in future. */
                            if(WriteCount!=TIFF_VARIABLE && WriteCount!=TIFF_VARIABLE2)
-                               break;					/* Fixed size arrays not handled. */
+                               break;                                   /* Fixed size arrays not handled. */
                            if(Value+4*Long2>=profile_length-1) break;
                            if(Long2==0) break;
                            Array = MagickAllocateResourceLimitedMemory(magick_uint32_t *, 4*Long2);
@@ -4632,11 +4633,11 @@
                                Array[i] = LD_UINT32(profile_data+Value+4*i);
                            if(WriteCount==TIFF_VARIABLE)
                            {
-                             if(TIFFSetField(tiff, Tag, (int)Long2, Array))	/* Argument 3 type int, argument 4 uint32_t*. */
+                             if(TIFFSetField(tiff, Tag, (int)Long2, Array))     /* Argument 3 type int, argument 4 uint32_t*. */
                                FieldCount++;
                            } else if(WriteCount==TIFF_VARIABLE2)
                            {
-                             if(TIFFSetField(tiff, Tag, Long2, Array))		 /* Argument 3 type uint32_t, argument 4 uint32_t*. */
+                             if(TIFFSetField(tiff, Tag, Long2, Array))           /* Argument 3 type uint32_t, argument 4 uint32_t*. */
                                FieldCount++;
                            }
                            MagickFreeResourceLimitedMemory(Array);
@@ -4647,23 +4648,23 @@
             case TIFF_BYTE:
                          if(WriteCount!=1)
                          {
-                           if(FDT!=Field) break;			/* Incompatible array type, might be converted in future. */
+                           if(FDT!=Field) break;                        /* Incompatible array type, might be converted in future. */
                            if(WriteCount!=TIFF_VARIABLE && WriteCount!=TIFF_VARIABLE2)
                            {
-                             if((WriteCount<=0)||(Long2<(magick_uint32_t)WriteCount)) break;		/* Too small amount of mandatory items. */
-                             if(Long2<(magick_uint32_t)WriteCount) break;		/* Too small amount of mandatory items. */
+                             if((WriteCount<=0)||(Long2<(magick_uint32_t)WriteCount)) break;            /* Too small amount of mandatory items. */
+                             if(Long2<(magick_uint32_t)WriteCount) break;               /* Too small amount of mandatory items. */
                              if(Long2<=4)
                              {
-                               if(TIFFSetField(tiff, Tag, IFD_data+8))	/* Argument 3 uint8_t[4]. */
+                               if(TIFFSetField(tiff, Tag, IFD_data+8))  /* Argument 3 uint8_t[4]. */
                                  FieldCount++;
                              }
                              else
                              {
                                if(Value+Long2>=profile_length-1) break;
-                               if(TIFFSetField(tiff, Tag, profile_data+Value))	/* Argument 3 uint8_t[4]. */
+                               if(TIFFSetField(tiff, Tag, profile_data+Value))  /* Argument 3 uint8_t[4]. */
                                  FieldCount++;
                              }
-                             break;					/* Fixed size arrays not handled. */
+                             break;                                     /* Fixed size arrays not handled. */
                            }
                            if(Value+Long2>=profile_length-1) break;
                                /* No need to convert endianity for BYTES. */
@@ -4673,7 +4674,7 @@
                                FieldCount++;
                            } else if(WriteCount==TIFF_VARIABLE2)
                            {
-                             if(TIFFSetField(tiff, Tag, Long2, profile_data+Value))	/* Argument 3 type uint32_t, argument 4 uint8_t*. */
+                             if(TIFFSetField(tiff, Tag, Long2, profile_data+Value))     /* Argument 3 type uint32_t, argument 4 uint8_t*. */
                                FieldCount++;
                            }
                            break;
@@ -4698,14 +4699,14 @@
                          {
                            if(WriteCount>1)
                            {
-                             if(Long2<(magick_uint32_t)WriteCount) break;	/* Too small amount of mandatory items. */
-                             if(Value+8*WriteCount>=profile_length-1) break;	/* Array falls over blob boundary. */
+                             if(Long2<(magick_uint32_t)WriteCount) break;       /* Too small amount of mandatory items. */
+                             if(Value+8*WriteCount>=profile_length-1) break;    /* Array falls over blob boundary. */
 #if TIFFLIB_VERSION >= 20230609
                              {
                                int i;
                                switch(TIFFFieldSetGetSize(fip))
                                  {
-                                 case 8:		/* double array is required in input. */
+                                 case 8:                /* double array is required in input. */
                                    {
                                      double *ArrayD;
                                      ArrayD = MagickAllocateResourceLimitedMemory(double *, sizeof(double)*WriteCount);
@@ -4720,7 +4721,7 @@
                                      MagickFreeResourceLimitedMemory(ArrayD);
                                    }
                                    break;
-                                 case 4:		/* float array is required in input. */
+                                 case 4:                /* float array is required in input. */
                                    {
                                      float *ArrayF;
                                      ArrayF = MagickAllocateResourceLimitedMemory(float *, sizeof(float)*WriteCount);
@@ -4749,12 +4750,12 @@
                            }
                            break;
                          }
-                         else		/* Process as scalar. */
+                         else           /* Process as scalar. */
                          {
                            double d;
                            if(Value+8>=profile_length) break;
                            d = LD_UINT32(profile_data+Value+4);
-                           if(d==0) break;		/* Prevent division by 0. */
+                           if(d==0) break;              /* Prevent division by 0. */
                            d = LD_UINT32(profile_data+Value) / d;
                            if(TIFFSetField(tiff, Tag, d))
                                FieldCount++;
@@ -4764,9 +4765,9 @@
       }
 
 NextItem:
-      if(profile_length <= 12)   
+      if(profile_length <= 12)
           break;
-      profile_length -=12;
+      /* profile_length -=12; */
       IFD_data += 12;
       EntryNum--;
     }
@@ -4795,7 +4796,7 @@