GraphicsMagick: ReadWPGImage(): If a colormap is provided, make ...

GraphicsMagick Commits <[email protected]> Sat, 14 Oct 2023 10:47:06 -0500
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.8594.1697298439.1370.graphicsmagick-commit@lists.sourceforge.net>
changeset 2fd2e662359d in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=2fd2e662359d
summary: ReadWPGImage(): If a colormap is provided, make sure that PsuedoClass indexes are initialized before promoting image to PseudoClass.

diffstat:

 ChangeLog                              |   8 ++++++++
 VisualMagick/installer/inc/version.isx |   4 ++--
 coders/wpg.c                           |  32 ++++++++++++++++++++++++++++++--
 magick/blob.c                          |   2 +-
 magick/version.h                       |   4 ++--
 www/Changelog.html                     |  10 ++++++++++
 6 files changed, 53 insertions(+), 7 deletions(-)

diffs (115 lines):

diff -r e981a3d54d22 -r 2fd2e662359d ChangeLog
--- a/ChangeLog	Mon Oct 09 20:24:59 2023 +0200
+++ b/ChangeLog	Sat Oct 14 10:47:04 2023 -0500
@@ -1,3 +1,11 @@
+2023-10-14  Bob Friesenhahn  <[email protected]>
+
+	* coders/wpg.c (ReadWPGImage): If a colormap is provided, make
+	sure that PsuedoClass indexes are initialized before promoting
+	image to PseudoClass. Addresses oss-fuzz issue 61394:
+	"graphicsmagick:coder_WPG_fuzzer: Use-of-uninitialized-value in
+	GrayscalePseudoClassImage".
+
 2023-10-08  Bob Friesenhahn  <[email protected]>
 
 	* coders/heif.c (ReadHEIFImage): Call heif_init() and
diff -r e981a3d54d22 -r 2fd2e662359d VisualMagick/installer/inc/version.isx
--- a/VisualMagick/installer/inc/version.isx	Mon Oct 09 20:24:59 2023 +0200
+++ b/VisualMagick/installer/inc/version.isx	Sat Oct 14 10:47:04 2023 -0500
@@ -10,5 +10,5 @@
 
 #define public MagickPackageName "GraphicsMagick"
 #define public MagickPackageVersion "1.4"
-#define public MagickPackageVersionAddendum ".020231008"
-#define public MagickPackageReleaseDate "snapshot-20231008"
+#define public MagickPackageVersionAddendum ".020231014"
+#define public MagickPackageReleaseDate "snapshot-20231014"
diff -r e981a3d54d22 -r 2fd2e662359d coders/wpg.c
--- a/coders/wpg.c	Mon Oct 09 20:24:59 2023 +0200
+++ b/coders/wpg.c	Sat Oct 14 10:47:04 2023 -0500
@@ -1602,9 +1602,37 @@
                    (((WPG_Palette.NumOfEntries-WPG_Palette.StartIndex) >
                      ((Rec2.RecordLength-2-2) / 3))) )
                  ThrowReaderException(CorruptImageError,InvalidColormapIndex,image);
-
+              /* Make sure that indexes contain initialized data if
+                 promoting from DirectClass.  This is a stop-gap
+                 measure until independent colormap support is
+                 developed. */
+              if (PseudoClass != image->storage_class)
+                {
+                  unsigned long y;
+                  IndexPacket *indexes;
+                  PixelPacket *p;
+                  MagickBool get = GetPixelCachePresent(image);
+                  image->storage_class = PseudoClass;
+                  for (y=0; y < image->rows; y++)
+                    {
+                      if (get)
+                        p=GetImagePixels(image,0,y,image->columns,1);
+                      else
+                        p=SetImagePixels(image,0,y,image->columns,1);
+                      if (p == (const PixelPacket *) NULL)
+                        break;
+                      indexes=AccessMutableIndexes(image);
+                      if (indexes == (IndexPacket *) NULL)
+                        break;
+                      (void) memset(indexes,0,sizeof(IndexPacket)*image->columns);
+                      if (!SyncImagePixels(image))
+                        break;
+                    }
+                  if (y != image->rows)
+                    ThrowReaderException(CacheError,UnableToGetPixelsFromCache,image);
+                }
               image->colors=WPG_Palette.NumOfEntries;
-              if (!AllocateImageColormap(image,image->colors)) /* FIXME: Oss-fuzz 61394, Trashes image->storage_class of previous image, which might be from ExtractPostscript()! */
+              if (!AllocateImageColormap(image,image->colors))
                 ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);
 
               for (i=WPG_Palette.StartIndex;
diff -r e981a3d54d22 -r 2fd2e662359d magick/blob.c
--- a/magick/blob.c	Mon Oct 09 20:24:59 2023 +0200
+++ b/magick/blob.c	Sat Oct 14 10:47:04 2023 -0500
@@ -2732,7 +2732,7 @@
     Form filename for multi-part images.
   */
   if (MagickSceneFileName(filename,image->filename,"",MagickFalse,
-                          GetImageIndexInList(image)))
+                          GetImageIndexInList(image))) /* FIXME: Could use image->scene */
     (void) strlcpy(image->filename,filename,MaxTextExtent);
 
   if (!image_info->adjoin)
diff -r e981a3d54d22 -r 2fd2e662359d magick/version.h
--- a/magick/version.h	Mon Oct 09 20:24:59 2023 +0200
+++ b/magick/version.h	Sat Oct 14 10:47:04 2023 -0500
@@ -38,8 +38,8 @@
 #define MagickLibVersion  0x272404
 #define MagickLibVersionText  "1.4"
 #define MagickLibVersionNumber 27,24,4
-#define MagickChangeDate   "20231008"
-#define MagickReleaseDate  "snapshot-20231008"
+#define MagickChangeDate   "20231014"
+#define MagickReleaseDate  "snapshot-20231014"
 
 /*
   The MagickLibInterfaceNewest and MagickLibInterfaceOldest defines
diff -r e981a3d54d22 -r 2fd2e662359d www/Changelog.html
--- a/www/Changelog.html	Mon Oct 09 20:24:59 2023 +0200
+++ b/www/Changelog.html	Sat Oct 14 10:47:04 2023 -0500
@@ -37,6 +37,16 @@
 </div>
 
 <div class="document">
+<p>2023-10-14  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/wpg.c (ReadWPGImage): If a colormap is provided, make
+sure that PsuedoClass indexes are initialized before promoting
+image to PseudoClass. Addresses oss-fuzz issue 61394:
+&quot;graphicsmagick:coder_WPG_fuzzer: Use-of-uninitialized-value in
+GrayscalePseudoClassImage&quot;.</p></li>
+</ul>
+</blockquote>
 <p>2023-10-08  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">