GraphicsMagick: coders/tiff.c Checking "TIFFFieldWriteCount(fip)...

GraphicsMagick Commits <[email protected]> Thu, 11 Jan 2024 19:41:57 -0600
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.2140.1705023730.19238.graphicsmagick-commit@lists.sourceforge.net>
changeset d0124d7b25cb in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=d0124d7b25cb
summary: coders/tiff.c Checking "TIFFFieldWriteCount(fip);" is much more safe.

diffstat:

 coders/tiff.c |  15 ++++-----------
 1 files changed, 4 insertions(+), 11 deletions(-)

diffs (40 lines):

diff -r 4f276520c791 -r d0124d7b25cb coders/tiff.c
--- a/coders/tiff.c	Fri Jan 12 01:58:08 2024 +0100
+++ b/coders/tiff.c	Fri Jan 12 02:41:35 2024 +0100
@@ -4520,6 +4520,7 @@
       if(fip!=NULL && (Flags & FLAG_BASE)!= 0)		/* libtiff doesn't understand these */
       {
         const TIFFDataType FDT = TIFFFieldDataType(fip);
+        const int WriteCount = TIFFFieldWriteCount(fip);
         switch(Field)
         {
           case TIFF_ASCII:
@@ -4554,7 +4555,8 @@
 /*            case TIFF_SRATIONAL:
                          break; */
             case TIFF_RATIONAL:
-                         if(Tag==EXIFTAG_LENSSPECIFICATION) break; // Needs 4 float values, will be implemented later
+                         if(WriteCount!=1)
+                             break;
 
                          if(FDT==TIFF_RATIONAL)
                          {
@@ -4563,17 +4565,8 @@
                            d = LD_UINT32(profile_data+Value+4);
                            if(d==0) break;		/* Prevent division by 0. */
                            d = LD_UINT32(profile_data+Value) / d;
-                           if(Tag==TIFFTAG_XRESOLUTION || Tag==TIFFTAG_YRESOLUTION)
-                           {
-                             const float f = d;
-                             if(TIFFSetField(tiff, Tag, f))
+                           if(TIFFSetField(tiff, Tag, d))
                                FieldCount++;
-                           }
-                           else
-                           {
-                             if(TIFFSetField(tiff, Tag, d))
-                               FieldCount++;
-                           }
                          }
                          break;
         }