GraphicsMagick: Fix Coverity issue 381864 "BAD_SHIFT".

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.14865.1667942558.1567.graphicsmagick-commit@lists.sourceforge.net>
changeset a9598ac346e3 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=a9598ac346e3
summary: Fix Coverity issue 381864 "BAD_SHIFT".

diffstat:

 ChangeLog          |   3 +++
 coders/png.c       |  14 ++++++++------
 www/Changelog.html |   2 ++
 3 files changed, 13 insertions(+), 6 deletions(-)

diffs (55 lines):

diff -r 867fb2e8d253 -r a9598ac346e3 ChangeLog
--- a/ChangeLog	Tue Nov 08 15:01:41 2022 -0600
+++ b/ChangeLog	Tue Nov 08 15:22:29 2022 -0600
@@ -1,5 +1,8 @@
 2022-11-08  Bob Friesenhahn  <[email protected]>
 
+	* coders/png.c (ReadOnePNGImage): Fix Coverity issue 381864
+	"BAD_SHIFT".
+
 	* magick/operator.c (QuantumDepthCB): Fix Coverity issue 381867
 	"Control flow issues (DEADCODE)".
 	(QuantumPowCB): Fix Coverity issue 381865 "Control flow issues
diff -r 867fb2e8d253 -r a9598ac346e3 coders/png.c
--- a/coders/png.c	Tue Nov 08 15:01:41 2022 -0600
+++ b/coders/png.c	Tue Nov 08 15:22:29 2022 -0600
@@ -2158,9 +2158,10 @@
 #endif
 
   if (png_get_valid(ping, ping_info, PNG_INFO_tRNS) &&
-      (ping_trans_color != (png_color_16p) NULL))
-    {
-      int
+      (ping_trans_color != (png_color_16p) NULL) &&
+      (unsigned int) ping_file_depth <= MaxColormapSize)
+    {
+      unsigned int
         bit_mask;
 
       if (logging != MagickFalse)
@@ -2242,9 +2243,10 @@
   image->compression=ZipCompression;
   image->columns=ping_width;
   image->rows=ping_height;
-  if ((ping_colortype == PNG_COLOR_TYPE_PALETTE) ||
-      (ping_colortype == PNG_COLOR_TYPE_GRAY_ALPHA) ||
-      (ping_colortype == PNG_COLOR_TYPE_GRAY))
+  if (((unsigned int) ping_file_depth <= MaxColormapSize) &&
+      ((ping_colortype == PNG_COLOR_TYPE_PALETTE) ||
+       (ping_colortype == PNG_COLOR_TYPE_GRAY_ALPHA) ||
+       (ping_colortype == PNG_COLOR_TYPE_GRAY)))
     {
       image->storage_class=PseudoClass;
       image->colors=1U << ping_file_depth;
diff -r 867fb2e8d253 -r a9598ac346e3 www/Changelog.html
--- a/www/Changelog.html	Tue Nov 08 15:01:41 2022 -0600
+++ b/www/Changelog.html	Tue Nov 08 15:22:29 2022 -0600
@@ -40,6 +40,8 @@
 <p>2022-11-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">
+<li><p>coders/png.c (ReadOnePNGImage): Fix Coverity issue 381864
+&quot;BAD_SHIFT&quot;.</p></li>
 <li><p>magick/operator.c (QuantumDepthCB): Fix Coverity issue 381867
 &quot;Control flow issues (DEADCODE)&quot;.
 (QuantumPowCB): Fix Coverity issue 381865 &quot;Control flow issues
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.