GraphicsMagick: TOPOL: Eliminate warnings and add some more erro...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.831.1683303127.1366.graphicsmagick-commit@lists.sourceforge.net>
changeset 866e04ffa779 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=866e04ffa779
summary: TOPOL: Eliminate warnings and add some more error checks

diffstat:

 ChangeLog          |   5 +++++
 coders/topol.c     |  27 +++++++++++++++++++++------
 www/Changelog.html |   7 +++++++
 3 files changed, 33 insertions(+), 6 deletions(-)

diffs (129 lines):

diff -r 7ceef82ce247 -r 866e04ffa779 ChangeLog
--- a/ChangeLog	Thu May 04 20:47:33 2023 -0500
+++ b/ChangeLog	Fri May 05 11:11:54 2023 -0500
@@ -1,3 +1,8 @@
+2023-05-05  Bob Friesenhahn  <[email protected]>
+
+	* coders/topol.c: Eliminate warnings and add some more error
+	checks.
+
 2023-05-05  Fojtik Jaroslav  <[email protected]>
 
 	* coders/topol.c: Fix memory leak.
diff -r 7ceef82ce247 -r 866e04ffa779 coders/topol.c
--- a/coders/topol.c	Thu May 04 20:47:33 2023 -0500
+++ b/coders/topol.c	Fri May 05 11:11:54 2023 -0500
@@ -1,5 +1,5 @@
 /*
-% Copyright (C) 2003-2022 GraphicsMagick Group
+% Copyright (C) 2003-2023 GraphicsMagick Group
 %
 % This program is covered by multiple licenses, which are described in
 % Copyright.txt. You should have received a copy of Copyright.txt with this
@@ -420,7 +420,7 @@
     status;
 
   size_t i;
-  unsigned long j;
+  long j;
   long ldblk;
 
   unsigned char
@@ -551,7 +551,7 @@
   /* ----- Handle the reindexing mez file ----- */
   j = image->colors;
   if(j<=0 || j>256) j=256;
-  for(i=0; i<j; i++)
+  for(i=0; i<(size_t) j; i++)
   {
     MEZ[i] = (unsigned char)((i*255) / (j-1));
   }
@@ -630,7 +630,7 @@
           image->colors = ldblk+1;
       if(!AllocateImageColormap(image, image->colors)) goto NoMemory;
 
-      for(i=0;i<=ldblk;i++)
+      for(i=0;i<=(size_t) ldblk;i++)
       {
         j = ReadBlobByte(palette);      /* Flag */
         if(j==EOF) break;               /* unexpected end of file */
@@ -824,6 +824,7 @@
   size_t DataSize;
   QuantumType qt;
   int bpp;
+  ExportPixelAreaInfo export_info;
 
 	/* Open output image file. */
   assert(image_info != (const ImageInfo *) NULL);
@@ -872,6 +873,8 @@
   if(DataSize==0)
     ThrowWriterException(FileOpenError,UnableToOpenFile,image);
   pixels = MagickAllocateResourceLimitedMemory(unsigned char *,(size_t) (DataSize));
+  if (pixels == (unsigned char *) NULL)
+    ThrowWriterException(ResourceLimitError,MemoryAllocationFailed,image);
 
   status = OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
   if(status == MagickFail)
@@ -900,6 +903,8 @@
   WriteBlobByte(image, Header.TileCompression);
 
   WriteBlob(image, 423, Header.Dummy);
+  if (GetBlobStatus(image))
+     ThrowWriterException(FileOpenError,UnableToWriteFile,image);
 
 	/* Store image data. */
   for(y=0; y<(long)image->rows; y++)
@@ -909,7 +914,12 @@
       status=MagickFail;
       break;
     }
-    if(ExportImagePixelArea(image,qt,bpp,pixels,0,0) != MagickPass)
+    if(ExportImagePixelArea(image,qt,bpp,pixels,0,&export_info) != MagickPass)
+    {
+      status = MagickFail;
+      break;
+    }
+    if (DataSize != export_info.bytes_exported)
     {
       status = MagickFail;
       break;
@@ -921,9 +931,13 @@
     }
   }
 
-  CloseBlob(image);
+  CloseBlob(image); /* valgrind reports write of unitialized data */
   MagickFreeResourceLimitedMemory(pixels);
 
+  if (y != (long)image->rows)
+    ThrowWriterException(FileOpenError,UnableToWriteFile,image);
+
+
 	/* Palette */
   if(qt == IndexQuantum)
   {
@@ -962,6 +976,7 @@
                 WriteBlobByte(Palette,ScaleQuantumToChar(image->colormap[i].blue));
               }
             }
+            CloseBlob(Palette);
           }
           DestroyImage(Palette);
         }
diff -r 7ceef82ce247 -r 866e04ffa779 www/Changelog.html
--- a/www/Changelog.html	Thu May 04 20:47:33 2023 -0500
+++ b/www/Changelog.html	Fri May 05 11:11:54 2023 -0500
@@ -37,6 +37,13 @@
 </div>
 
 <div class="document">
+<p>2023-05-05  Bob Friesenhahn  &lt;<a class="reference external" href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#64;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
+<blockquote>
+<ul class="simple">
+<li><p>coders/topol.c: Eliminate warnings and add some more error
+checks.</p></li>
+</ul>
+</blockquote>
 <p>2023-05-05  Fojtik Jaroslav  &lt;<a class="reference external" href="mailto:JaFojtik&#37;&#52;&#48;yandex&#46;com">JaFojtik<span>&#64;</span>yandex<span>&#46;</span>com</a>&gt;</p>
 <blockquote>
 <ul class="simple">
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.