GraphicsMagick: ReadTIFFImage(): Verify that the bits per sample...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.287.1684605267.17398.graphicsmagick-commit@lists.sourceforge.net>
changeset 40a065fab214 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=40a065fab214
summary: ReadTIFFImage(): Verify that the bits per sample, samples per pixel, and photometric are suitable for the claimed compressor

diffstat:

 ChangeLog          |   5 +-
 coders/tiff.c      |  85 +++++++++++++++++++++++++++++++++++++++++++----------
 www/Changelog.html |   5 +-
 3 files changed, 74 insertions(+), 21 deletions(-)

diffs (139 lines):

diff -r 279b3aa0832a -r 40a065fab214 ChangeLog
--- a/ChangeLog	Sat May 20 11:15:31 2023 -0500
+++ b/ChangeLog	Sat May 20 12:54:08 2023 -0500
@@ -1,7 +1,8 @@
 2023-05-20  Bob Friesenhahn  <[email protected]>
 
-	* coders/tiff.c (ReadTIFFImage): Verify that the bits per sample
-	is suitable for the claimed compressor.
+	* coders/tiff.c (ReadTIFFImage): Verify that the bits per sample,
+	samples per pixel, and photometric are suitable for the claimed
+	compressor.
 
 	* coders/bmp.c (ReadBMPImage): Do not decode primaries or gamma
 	unless colorspace is LCS_CALIBRATED_RGB.
diff -r 279b3aa0832a -r 40a065fab214 coders/tiff.c
--- a/coders/tiff.c	Sat May 20 11:15:31 2023 -0500
+++ b/coders/tiff.c	Sat May 20 12:54:08 2023 -0500
@@ -2396,38 +2396,89 @@
         }
 
       /*
-        Verify that the bits per sample is suitable for the claimed compressor
+        Verify that the bits per sample, samples per pixel, and
+        photometric are suitable for the claimed compressor
       */
 #if defined(COMPRESSION_CCITTFAX3)
-      if ((COMPRESSION_CCITTFAX3 == compress_tag) && (1 != bits_per_sample))
+      if (COMPRESSION_CCITTFAX3 == compress_tag)
         {
-          (void) LogMagickEvent(CoderEvent,GetMagickModule(),
-                                "CCITT FAX3 compression requires 1 bits per sample!");
-          ThrowTIFFReaderException(CoderError,UnsupportedBitsPerSample,image);
+          if (1 != bits_per_sample)
+            {
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "%s compression requires 1 bits per sample!",
+                                    CompressionTagToString(compress_tag));
+              ThrowTIFFReaderException(CorruptImageError,ImproperImageHeader,image);
+            {
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "%s compression requires photometric of minisblack or miniswhite!",
+                                    CompressionTagToString(compress_tag));
+              ThrowTIFFReaderException(CorruptImageError,ImproperImageHeader,image);
+            }
+            }
         }
 #endif /* if defined(COMPRESSION_CCITTFAX3) */
 #if defined(COMPRESSION_CCITTFAX4)
-      if ((COMPRESSION_CCITTFAX4 == compress_tag) && (1 != bits_per_sample))
+      if (COMPRESSION_CCITTFAX4 == compress_tag)
         {
-          (void) LogMagickEvent(CoderEvent,GetMagickModule(),
-                                "CCITT FAX4 compression requires 1 bits per sample!");
-          ThrowTIFFReaderException(CoderError,UnsupportedBitsPerSample,image);
+          if (1 != bits_per_sample)
+            {
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "%s compression requires 1 bits per sample!",
+                                    CompressionTagToString(compress_tag));
+              ThrowTIFFReaderException(CorruptImageError,ImproperImageHeader,image);
+            }
+          if ((PHOTOMETRIC_MINISBLACK != photometric) && (PHOTOMETRIC_MINISWHITE != photometric))
+            {
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "%s compression requires photometric of minisblack or miniswhite!",
+                                    CompressionTagToString(compress_tag));
+              ThrowTIFFReaderException(CorruptImageError,ImproperImageHeader,image);
+            }
         }
 #endif /* if defined(COMPRESSION_CCITTFAX4) */
 #if defined(COMPRESSION_JBIG)
-      if ((COMPRESSION_JBIG == compress_tag) && (1 != bits_per_sample))
+      if (COMPRESSION_JBIG == compress_tag)
         {
-          (void) LogMagickEvent(CoderEvent,GetMagickModule(),
-                                "JBIG compression requires 1 bits per sample!");
-          ThrowTIFFReaderException(CoderError,UnsupportedBitsPerSample,image);
+          if (1 != bits_per_sample)
+            {
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "%s compression requires 1 bits per sample!",
+                                    CompressionTagToString(compress_tag));
+              ThrowTIFFReaderException(CorruptImageError,ImproperImageHeader,image);
+            }
+          if ((PHOTOMETRIC_MINISBLACK != photometric) && (PHOTOMETRIC_MINISWHITE != photometric))
+            {
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "%s compression requires photometric of minisblack or miniswhite!",
+                                    CompressionTagToString(compress_tag));
+              ThrowTIFFReaderException(CorruptImageError,ImproperImageHeader,image);
+            }
         }
 #endif /* if defined(COMPRESSION_JBIG) */
 #if defined(COMPRESSION_WEBP)
-      if ((COMPRESSION_WEBP == compress_tag) && (8 != bits_per_sample))
+      if (COMPRESSION_WEBP == compress_tag)
         {
-          (void) LogMagickEvent(CoderEvent,GetMagickModule(),
-                                "WebP compression requires 8 bits per sample!");
-          ThrowTIFFReaderException(CoderError,UnsupportedBitsPerSample,image);
+          if (8 != bits_per_sample)
+            {
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "%s compression requires 8 bits per sample!",
+                                    CompressionTagToString(compress_tag));
+              ThrowTIFFReaderException(CorruptImageError,ImproperImageHeader,image);
+            }
+          if ((3 != samples_per_pixel) && (4 != samples_per_pixel))
+            {
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "%s compression requires 3 or 4 samples per pixel!",
+                                    CompressionTagToString(compress_tag));
+              ThrowTIFFReaderException(CorruptImageError,ImproperImageHeader,image);
+            }
+          if (PHOTOMETRIC_RGB != photometric)
+            {
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "%s compression requires photometric RGB!",
+                                    CompressionTagToString(compress_tag));
+              ThrowTIFFReaderException(CorruptImageError,ImproperImageHeader,image);
+            }
         }
 #endif /* if defined(COMPRESSION_WEBP) */
 
diff -r 279b3aa0832a -r 40a065fab214 www/Changelog.html
--- a/www/Changelog.html	Sat May 20 11:15:31 2023 -0500
+++ b/www/Changelog.html	Sat May 20 12:54:08 2023 -0500
@@ -40,8 +40,9 @@
 <p>2023-05-20  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/tiff.c (ReadTIFFImage): Verify that the bits per sample
-is suitable for the claimed compressor.</p></li>
+<li><p>coders/tiff.c (ReadTIFFImage): Verify that the bits per sample,
+samples per pixel, and photometric are suitable for the claimed
+compressor.</p></li>
 <li><p>coders/bmp.c (ReadBMPImage): Do not decode primaries or gamma
 unless colorspace is LCS_CALIBRATED_RGB.</p></li>
 </ul>
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.