GraphicsMagick: 3 new changesets

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.44020.1640481235.2008.graphicsmagick-commit@lists.sourceforge.net>
changeset 083c790c4850 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=083c790c4850
summary: PNG: Support the define png:chunk-malloc-max=limit in order to adjust libpng's chunk size limit.

changeset a9da84c341f5 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=a9da84c341f5
summary: JP2: Fix recently added memory leak pertaining to options

changeset ba930c1fc380 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=ba930c1fc380
summary: JPEG: Implement more efficient way to append JPEG profile chunks.

diffstat:

 ChangeLog                              |    22 +
 VisualMagick/installer/inc/version.isx |     4 +-
 coders/jp2.c                           |     2 +
 coders/jpeg.c                          |   104 +-
 coders/png.c                           |    30 +-
 doc/options.imdoc                      |    10 +
 magick/profile.h                       |     2 +-
 magick/version.h                       |     4 +-
 utilities/gm.1                         |  3286 ++++++++++++++++---------------
 www/Changelog.html                     |    19 +
 www/GraphicsMagick.html                |    23 +-
 www/animate.html                       |    14 +-
 www/batch.html                         |     4 +-
 www/benchmark.html                     |     4 +-
 www/compare.html                       |     4 +-
 www/composite.html                     |     4 +-
 www/conjure.html                       |     4 +-
 www/convert.html                       |     6 +-
 www/display.html                       |    48 +-
 www/gm.html                            |   125 +-
 www/identify.html                      |     4 +-
 www/import.html                        |     4 +-
 www/mogrify.html                       |     6 +-
 www/montage.html                       |     8 +-
 www/time.html                          |     4 +-
 www/version.html                       |     4 +-
 26 files changed, 1970 insertions(+), 1779 deletions(-)

diffs (truncated from 10092 to 500 lines):

diff -r 3c58991d3b9b -r ba930c1fc380 ChangeLog
--- a/ChangeLog	Fri Dec 24 17:28:54 2021 -0600
+++ b/ChangeLog	Sat Dec 25 19:10:32 2021 -0600
@@ -1,3 +1,25 @@
+2021-12-25  Bob Friesenhahn  <[email protected]>
+
+        * magick/profile.c (AppendImageProfile): Deprecate this function
+        since JPEG was the last user.
+
+        * coders/jpeg.c (AppendProfile): Implement more efficient way to
+        append JPEG profile chunks.  Addresses SourceForge issue #634
+        "Slow to read JPEG with big APP1 profile".
+
+        * coders/jp2.c (ReadJP2Image): Free 'options' which is now
+        allocated memory.
+
+        * coders/png.c (ReadOnePNGImage): Support the define
+        png:chunk-malloc-max=limit in order to allow reading PNG files
+        which report "chunk data is too large" or to reduce the default
+        limit.  The default libpng limit is 8,000,000 bytes, which is more
+        than sufficient for normal files.  Note that since PNG uses
+        compression, the limit is on the uncompressed data and a
+        relatively small file may be able to provide a chunk which
+        decompresses to a large size.  Addresses SourceForge #594 "Be able
+        to affect libpng user_chunk_malloc_max".
+
 2021-12-24  Bob Friesenhahn  <[email protected]>
 
         * PerlMagick/Magick.xs: Fix issue that image fill attribute had
diff -r 3c58991d3b9b -r ba930c1fc380 VisualMagick/installer/inc/version.isx
--- a/VisualMagick/installer/inc/version.isx	Fri Dec 24 17:28:54 2021 -0600
+++ b/VisualMagick/installer/inc/version.isx	Sat Dec 25 19:10:32 2021 -0600
@@ -10,5 +10,5 @@
 
 #define public MagickPackageName "GraphicsMagick"
 #define public MagickPackageVersion "1.4"
-#define public MagickPackageVersionAddendum ".020211224"
-#define public MagickPackageReleaseDate "snapshot-20211224"
+#define public MagickPackageVersionAddendum ".020211225"
+#define public MagickPackageReleaseDate "snapshot-20211225"
diff -r 3c58991d3b9b -r ba930c1fc380 coders/jp2.c
--- a/coders/jp2.c	Fri Dec 24 17:28:54 2021 -0600
+++ b/coders/jp2.c	Sat Dec 25 19:10:32 2021 -0600
@@ -783,6 +783,8 @@
     }
 #endif /* if HAVE_PGX_DECODE */
 
+  MagickFreeMemory(options);
+
   /*
     Using jas_image_decode() makes us subject to Jasper's own format
     determination, which may include file formats we don't want to
diff -r 3c58991d3b9b -r ba930c1fc380 coders/jpeg.c
--- a/coders/jpeg.c	Fri Dec 24 17:28:54 2021 -0600
+++ b/coders/jpeg.c	Sat Dec 25 19:10:32 2021 -0600
@@ -172,6 +172,9 @@
   int
     max_scan_number;
 
+  ProfileInfo
+    profiles[16];
+
   unsigned char
     buffer[65537+200];
 
@@ -204,10 +207,79 @@
 
 static MagickClientData *FreeMagickClientData(MagickClientData *client_data)
 {
+  unsigned int
+    i;
+
+  /* Free profiles data */
+  for (i=0 ; i < ArraySize(client_data->profiles); i++)
+    {
+      MagickFreeMemory(client_data->profiles[i].name);
+      MagickFreeResourceLimitedMemory(client_data->profiles[i].info);
+    }
+
   MagickFreeMemory(client_data);
   return client_data;
 }
 
+/* Append named profile to profiles in client data. */
+static MagickPassFail
+AppendProfile(MagickClientData *client_data,
+              const char *name,
+              const unsigned char *profile_chunk,
+              const size_t chunk_length)
+{
+  unsigned int
+    i;
+
+  /*
+    If entry with matching name is found, then add/append data to
+    profile 'info' and update profile length
+  */
+  for (i=0 ; i < ArraySize(client_data->profiles); i++)
+    {
+      ProfileInfo *profile=&client_data->profiles[i];
+      if (!profile->name)
+        break;
+      if (strcmp(profile->name,name) == 0)
+        {
+          const size_t new_length = profile->length+chunk_length;
+          unsigned char *info = MagickReallocateResourceLimitedMemory(unsigned char *,
+                                                                      profile->info,new_length);
+          if (info != (unsigned char *) NULL)
+            {
+              profile->info = info;
+              (void) memcpy(profile->info+profile->length,profile_chunk,chunk_length);
+              profile->length=new_length;
+              return MagickPass;
+            }
+        }
+    }
+
+
+  /*
+    If no matching entry, then find unallocated entry, add data to
+     profile 'info' and update profile length
+  */
+  for (i=0 ; i < ArraySize(client_data->profiles); i++)
+    {
+      ProfileInfo *profile=&client_data->profiles[i];
+      if (profile->name)
+        continue;
+      profile->name=AcquireString(name);
+      profile->info=MagickAllocateResourceLimitedMemory(unsigned char*,chunk_length);
+      if (!profile->name || !profile->info)
+        {
+          MagickFreeMemory(profile->name);
+          MagickFreeResourceLimitedMemory(profile->info);
+          break;
+        }
+      (void) memcpy(profile->info,profile_chunk,chunk_length);
+      profile->length=chunk_length;
+      return MagickPass;
+    }
+  return MagickFail;
+}
+
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
@@ -533,9 +605,6 @@
   MagickClientData
     *client_data;
 
-  Image
-    *image;
-
   size_t
     header_length=0,
     length;
@@ -588,7 +657,6 @@
     Obtain Image.
   */
   client_data=(MagickClientData *) jpeg_info->client_data;
-  image=client_data->image;
 
   /*
     Copy profile from JPEG to allocated memory.
@@ -627,7 +695,7 @@
   /*
     Store profile in Image.
   */
-  (void) AppendImageProfile(image,profile_name,profile+header_length,
+  (void) AppendProfile(client_data,profile_name,profile+header_length,
                             length-header_length);
 
   (void) LogMagickEvent(CoderEvent,GetMagickModule(),
@@ -647,9 +715,6 @@
   MagickClientData
     *client_data;
 
-  Image
-    *image;
-
   unsigned char
     *profile;
 
@@ -688,7 +753,6 @@
   (void) GetCharacter(jpeg_info);  /* markers */
   length-=14;
   client_data=(MagickClientData *) jpeg_info->client_data;
-  image=client_data->image;
 
   /*
     Read color profile.
@@ -707,7 +771,7 @@
         break;
     }
   if (i == length)
-    (void) AppendImageProfile(image,"ICM",profile,length);
+    (void) AppendProfile(client_data,"ICM",profile,length);
 
   return(True);
 }
@@ -816,7 +880,7 @@
         break;
     }
   if (i == length)
-    (void) AppendImageProfile(image,"IPTC",profile,length);
+    (void) AppendProfile(client_data,"IPTC",profile,length);
 
   return(True);
 }
@@ -1177,7 +1241,7 @@
   const char
     *value;
 
-  register long
+  register unsigned long
     i;
 
   struct jpeg_error_mgr
@@ -1769,6 +1833,22 @@
     }
   jpeg_destroy_decompress(&jpeg_info);
   MagickFreeResourceLimitedMemory(jpeg_pixels);
+
+  /*
+    Store profiles in image.
+  */
+  for (i=0 ; i < ArraySize(client_data->profiles); i++)
+    {
+      ProfileInfo *profile=&client_data->profiles[i];
+      if (!profile->name)
+        continue;
+      if (!profile->length)
+        continue;
+      if (!profile->info)
+        continue;
+      (void) SetImageProfile(image,profile->name,profile->info,profile->length);
+    }
+
   client_data=FreeMagickClientData(client_data);
   CloseBlob(image);
 
diff -r 3c58991d3b9b -r ba930c1fc380 coders/png.c
--- a/coders/png.c	Fri Dec 24 17:28:54 2021 -0600
+++ b/coders/png.c	Sat Dec 25 19:10:32 2021 -0600
@@ -1656,13 +1656,39 @@
   png_set_benign_errors(ping, 1);
 #endif
 
-  /* Just use libpng's limit (PNG_USER_CHUNK_MALLOC_MAX == 8000000) on
-     chunk size */
+  /* Default to using libpng's limit (PNG_USER_CHUNK_MALLOC_MAX ==
+     8000000) on chunk size */
 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
   /* Reject images with too many rows or columns */
   png_set_user_limits(ping,
     (png_uint_32) Min(0x7fffffffL, GetMagickResourceLimit(WidthResource)),
     (png_uint_32) Min(0x7fffffffL, GetMagickResourceLimit(HeightResource)));
+  /* Allow specifying a different chunk size limit than the
+     PNG_USER_CHUNK_MALLOC_MAX baked into libpng */
+# if PNG_LIBPNG_VER >= 10401 /* png_set_chunk_malloc_max was added in 1.4.1 */
+  {
+    const char *chunk_malloc_max_str;
+    if ((chunk_malloc_max_str=AccessDefinition(image_info,"png","chunk-malloc-max")))
+      {
+        unsigned long chunk_malloc_max;
+        if (MagickAtoULChk(chunk_malloc_max_str, &chunk_malloc_max) == MagickPass)
+          {
+            png_set_chunk_malloc_max(ping, chunk_malloc_max);
+            if (logging)
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "Set PNG chunk-malloc-max to %lu bytes",
+                                    chunk_malloc_max);
+          }
+        else
+          {
+            if (logging)
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "Failed to parse chunk-malloc-max value \"%s\"",
+                                    chunk_malloc_max_str);
+          }
+      }
+  }
+# endif
 #endif /* PNG_SET_USER_LIMITS_SUPPORTED */
 
   (void) LogMagickEvent(CoderEvent,GetMagickModule(),
diff -r 3c58991d3b9b -r ba930c1fc380 doc/options.imdoc
--- a/doc/options.imdoc	Fri Dec 24 17:28:54 2021 -0600
+++ b/doc/options.imdoc	Sat Dec 25 19:10:32 2021 -0600
@@ -1258,6 +1258,16 @@
 requested to scale the image to fit the page size (width and/or
 height).</dd>
 
+<dt>png:chunk-malloc-max=<value></dt>
+<dd>png:chunk-malloc-max specifies the maximum chunk size that libpng
+will be allowed to read.  Libpng's default is normally 8,000,000
+bytes. Very rarely, a valid PNG file may be encountered where the
+error is reported "chunk data is too large".  In this case, the limit
+may be increased using this option.  Take care when increasing this
+limit since an excessively large limit could allow untrusted files to
+use excessive memory.
+</dd>
+
 <dt>mng:maximum-loops=<value></dt>
 <dd>mng:maximum-loops specifies the maximum number of loops allowed to
 be specified by a MNG LOOP chunk. Without an imposed limit, a MNG file
diff -r 3c58991d3b9b -r ba930c1fc380 magick/profile.h
--- a/magick/profile.h	Fri Dec 24 17:28:54 2021 -0600
+++ b/magick/profile.h	Sat Dec 25 19:10:32 2021 -0600
@@ -46,7 +46,7 @@
   extern MagickExport MagickPassFail
   AppendImageProfile(Image *image,const char *name,
                      const unsigned char *profile_chunk,
-                     const size_t chunk_length);
+                     const size_t chunk_length) MAGICK_FUNC_DEPRECATED;
 
 /*
   Generic iterator for traversing profiles.
diff -r 3c58991d3b9b -r ba930c1fc380 magick/version.h
--- a/magick/version.h	Fri Dec 24 17:28:54 2021 -0600
+++ b/magick/version.h	Sat Dec 25 19:10:32 2021 -0600
@@ -38,8 +38,8 @@
 #define MagickLibVersion  0x262300
 #define MagickLibVersionText  "1.4"
 #define MagickLibVersionNumber 26,23,0
-#define MagickChangeDate   "20211224"
-#define MagickReleaseDate  "snapshot-20211224"
+#define MagickChangeDate   "20211225"
+#define MagickReleaseDate  "snapshot-20211225"
 
 /*
   The MagickLibInterfaceNewest and MagickLibInterfaceOldest defines
diff -r 3c58991d3b9b -r ba930c1fc380 utilities/gm.1
--- a/utilities/gm.1	Fri Dec 24 17:28:54 2021 -0600
+++ b/utilities/gm.1	Sat Dec 25 19:10:32 2021 -0600
@@ -1,68 +1,68 @@
-.TH gm 1 "2021/01/29" "GraphicsMagick"
+.TH gm 1 "2021/12/25" "GraphicsMagick"
 .TP
 .in 15
 .in 15
 .in 20
 .SH NAME
-
+\'
 gm - command-line utility to create, edit, compare, convert, or display images
-
+\'
 .SH SYNOPSIS
-
+\'
 \fBgm animate\fP \fB[\fP \fIoptions ...\fP \fB]\fP \fIfile\fP \fB[ [\fP
 \fIoptions ...\fP \fB]\fP \fIfile ...\fP \fB]\fP
-
+\'
 \fBgm batch\fP \fB[\fP \fIoptions ...\fP \fB]\fP \fB[\fP \fIscript\fP \fB]\fP
-
+\'
 \fBgm benchmark\fP \fB[\fP \fIoptions ...\fP \fB]\fP subcommand
-
+\'
 \fBgm compare\fP \fB[\fP \fIoptions\fP \fB... ]\fP \fIreference-image\fP
 \fB[\fP \fIoptions\fP \fB... ]\fP \fIcompare-image\fP
 \fB[\fP \fIoptions\fP \fB... ]\fP
-
+\'
 \fBgm composite\fP \fB[\fP \fIoptions ...\fP \fB]\fP \fIchange-image base-image\fP
 \fB[\fP \fImask-image\fP \fB]\fP \fIoutput-image\fP
-
+\'
 \fBgm conjure\fP \fB[\fP \fIoptions\fP \fB]\fP \fIscript.msl\fP
 \fB[ [\fP \fIoptions\fP \fB]\fP \fIscript.msl\fP \fB]\fP
-
+\'
 \fBgm convert\fP \fB[ [\fP \fIoptions ...\fP \fB] [\fP \fIinput-file ...\fP
 \fB] [\fP \fIoptions ...\fP \fB] ]\fP \fIoutput-file\fP 
-
+\'
 \fBgm display\fP \fB[\fP \fIoptions ...\fP \fB]\fP \fIfile ...\fP
 \fB[ [\fP\fIoptions ...\fP \fB]\fP\fIfile ...\fP \fB]\fP
-
+\'
 \fBgm identify\fP \fIfile\fP \fB[\fP \fIfile ...\fP \fB]\fP
-
+\'
 \fBgm import\fP \fB[\fP \fIoptions ...\fP \fB]\fP \fIfile\fP
-
+\'
 \fBgm mogrify\fP \fB[\fP \fIoptions ...\fP \fB]\fP \fIfile ...\fP
-
+\'
 \fBgm montage\fP \fB[\fP \fIoptions ...\fP \fB]\fP \fIfile\fP \fB[ [\fP
 \fIoptions ...\fP \fB]\fP \fIfile ...\fP \fB]\fP \fIoutput-file\fP
-
+\'
 \fBgm time\fP subcommand
-
+\'
 \fBgm version\fP
 .SH DESCRIPTION
-
+\'
 GraphicsMagick's \fBgm\fP provides a suite of utilities for creating,
 comparing, converting, editing, and displaying images.  All of the
 utilities are provided as sub-commands of a single \fBgm\fP
 executable.  The \fBgm\fP executable returns the exit code 0 to
 indicate success, or 1 to indicate failure:
-
+\'
 \fBanimate\fP
 displays an animation (e.g. a GIF file) on any workstation display
 running an \fIX\fP server.
-
+\'
 \fBbatch\fP
 executes an arbitary number of the utility commands
 (e.g. \fBconvert\fP) in the form of a simple linear batch script in
 order to improve execution efficiency, and/or to allow use as a
 subordinate co-process under the control of an arbitrary script or
 program.
-
+\'
 \fBbenchmark\fP
 executes one of the other utility commands (e.g. \fBconvert\fP) for a
 specified number of iterations, or execution time, and reports
@@ -70,63 +70,63 @@
 utilization. \fBBenchmark\fP provides various operating modes
 including executing the command with a varying number of threads, and
 alternate reporting formats such as comma-separated value (CSV).
-
+\'
 \fBcompare\fP
 compares two images and reports difference statistics according to
 specified metrics and/or outputs an image with a visual representation
 of the differences.  It may also be used to test if images are similar
 within a particular range and specified metric, returning a truth
 value to the executing environment.
-
+\'
 \fBcomposite\fP
 composites images (blends or merges images together) to create new images.
-
+\'
 \fBconjure\fP
 interprets and executes scripts in
 the Magick Scripting Language (MSL).
-
+\'
 \fBconvert\fP
 converts an input file using one image format to an output file with
 the same or differing image format while applying an arbitrary number
 of image transformations.
-
+\'
 \fBdisplay\fP
 is a machine architecture independent image processing and display
 facility. It can display an image on any workstation display running
 an \fIX\fP server.
-
+\'
 \fBidentify\fP
 describes the format and characteristics of one or more image
 files. It will also report if an image is incomplete or corrupt.
-
+\'
 \fBimport\fP
 reads an image from any visible window on an \fIX\fP server and
 outputs it as an image file. You can capture a single window, the
 entire screen, or any rectangular portion of the screen.
-
+\'
 \fBmogrify\fP
 transforms an image or a sequence of images. These transforms include
 \fBimage scaling\fP, \fBimage rotation\fP, \fBcolor reduction\fP,
 and others. The transmogrified image \fBoverwrites\fP the original
 image.
-
+\'
 \fBmontage\fP
 creates a composite by combining several separate images. The images
 are tiled on the composite image with the name of the image optionally
 appearing just below the individual tile.
-
+\'
 \fBtime\fP
 executes a subcommand and reports the user, system, and total
 execution time consumed.
-
+\'
 \fBversion\fP
 reports the GraphicsMagick release version, maximum sample-depth,
 copyright notice, supported features, and the options used while
 building the software.
-
+\'
 The \fBGraphicsMagick\fP utilities recognize the following image formats:
-
-
+\'
+\'
 \fBName\fP  \fBMode\fP \fBDescription\fP
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.