GraphicsMagick: GenerateEXIFAttribute(): Assure that float and d...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.11450.1682781228.1830.graphicsmagick-commit@lists.sourceforge.net>
changeset ca23f27fe474 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=ca23f27fe474
summary: GenerateEXIFAttribute(): Assure that float and double values are suitably alligned

diffstat:

 ChangeLog          |  5 +++++
 coders/tiff.c      |  2 +-
 magick/attribute.c |  8 ++++++--
 3 files changed, 12 insertions(+), 3 deletions(-)

diffs (61 lines):

diff -r c9b750fbb01f -r ca23f27fe474 ChangeLog
--- a/ChangeLog	Sat Apr 29 09:45:49 2023 -0500
+++ b/ChangeLog	Sat Apr 29 10:13:35 2023 -0500
@@ -1,5 +1,10 @@
 2023-04-29  Bob Friesenhahn  <[email protected]>
 
+	* magick/attribute.c (GenerateEXIFAttribute): Assure that float
+	and double values are suitably alligned.  Addresses SourceForge
+	issue #709 "Undefined behavior while loading a value of type float
+	from an unaligned address".
+
 	* coders/tiff.c (ReadTIFFImage): Validate that TIFFGetField() did
 	return count and text rather than just relying on its return
 	status.  Addresses SourceForge issue #710 "Undefined behavior
diff -r c9b750fbb01f -r ca23f27fe474 coders/tiff.c
--- a/coders/tiff.c	Sat Apr 29 09:45:49 2023 -0500
+++ b/coders/tiff.c	Sat Apr 29 10:13:35 2023 -0500
@@ -1,5 +1,5 @@
 /*
-% Copyright (C) 2003 - 2022 GraphicsMagick Group
+% Copyright (C) 2003 - 2023 GraphicsMagick Group
 % Copyright (C) 2002 ImageMagick Studio
 % Copyright 1991-1999 E. I. du Pont de Nemours and Company
 %
diff -r c9b750fbb01f -r ca23f27fe474 magick/attribute.c
--- a/magick/attribute.c	Sat Apr 29 09:45:49 2023 -0500
+++ b/magick/attribute.c	Sat Apr 29 10:13:35 2023 -0500
@@ -2156,6 +2156,7 @@
                   }
                 case EXIF_FMT_SINGLE:
                   {
+                    float fval;
                     if ((pval < tiffp) || ((pval+sizeof(float)) > tiffp_max))
                       {
                         if (logging)
@@ -2164,12 +2165,14 @@
                                                 (MAGICK_SSIZE_T) (pval-tiffp));
                         goto generate_attribute_failure;
                       }
-                    FormatString(s,"%f",(double) *(float *) pval);
+                    (void) memcpy(&fval,pval,sizeof(fval));
+                    FormatString(s,"%f",(double) fval);
                     value=AllocateString(s);
                     break;
                   }
                 case EXIF_FMT_DOUBLE:
                   {
+                    double dval;
                     if ((pval < tiffp) || ((pval+sizeof(double)) > tiffp_max))
                       {
                         if (logging)
@@ -2178,7 +2181,8 @@
                                                 (MAGICK_SSIZE_T) (pval-tiffp));
                         goto generate_attribute_failure;
                       }
-                    FormatString(s,"%f",*(double *) pval);
+                    (void) memcpy(&dval,pval,sizeof(dval));
+                    FormatString(s,"%f",dval);
                     value=AllocateString(s);
                     break;
                   }
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.