PCL: Fix null pointer dereference in writing monochrome images.
authorBob Friesenhahn <bfriesen@GraphicsMagick.org>
Sat, 22 Jul 2017 19:51:32 -0500
changeset 15095 f3ffc5541257
parent 15094 db732abd9318
child 15096 d076c1cae88b
PCL: Fix null pointer dereference in writing monochrome images.
ChangeLog
coders/pcl.c
www/Changelog.html
--- a/ChangeLog	Sat Jul 22 17:56:27 2017 -0500
+++ b/ChangeLog	Sat Jul 22 19:51:32 2017 -0500
@@ -1,5 +1,9 @@
 2017-07-22  Bob Friesenhahn  <bfriesen@simple.dallas.tx.us>
 
+	* coders/pcl.c (WritePCLImage): Fix null pointer dereference in
+	PCL writer when writing monochrome images.  Problem was reported
+	by LCatro via email on July 18.
+
 	* magick/pixel_cache.c (PersistCache): Fix memory leak while
 	writing a MPC file.  Problem was reported by LCatro via email on
 	July 18.
--- a/coders/pcl.c	Sat Jul 22 17:56:27 2017 -0500
+++ b/coders/pcl.c	Sat Jul 22 19:51:32 2017 -0500
@@ -1010,7 +1010,16 @@
               for (x=0; x < (long) image->columns; x++)
                 {
                   byte<<=1;
-                  if (indexes[x] == blk_ind) byte |= 1;
+                  if (image->storage_class == PseudoClass)
+                    {
+                      if (indexes[x] == blk_ind)
+                        byte |= 1;
+                    }
+                  else
+                    {
+                      if (p[x].red == 0)
+                        byte |= 1;
+                    }
                   bit++;
                   if (bit == 8)
                     {
@@ -1028,10 +1037,20 @@
               /*
                 8 bit PseudoClass row
               */
-              indexes=AccessImmutableIndexes(image);
-              for (x=0; x < (long) image->columns; x++)
+              if (image->storage_class == PseudoClass)
                 {
-                  *q++=indexes[x];
+                  indexes=AccessImmutableIndexes(image);
+                  for (x=0; x < (long) image->columns; x++)
+                    {
+                      *q++=indexes[x];
+                    }
+                }
+              else
+                {
+                  for (x=0; x < (long) image->columns; x++)
+                    {
+                      *q++=PixelIntensityRec601(&p[x]);
+                    }
                 }
             }
           else
--- a/www/Changelog.html	Sat Jul 22 17:56:27 2017 -0500
+++ b/www/Changelog.html	Sat Jul 22 19:51:32 2017 -0500
@@ -38,6 +38,9 @@
 <p>2017-07-22  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>coders/pcl.c (WritePCLImage): Fix null pointer dereference in
+PCL writer when writing monochrome images.  Problem was reported
+by LCatro via email on July 18.</li>
 <li>magick/pixel_cache.c (PersistCache): Fix memory leak while
 writing a MPC file.  Problem was reported by LCatro via email on
 July 18.</li>