]> granicus.if.org Git - imagemagick/commitdiff
Fixed bug with writing tIME chunk when timezone has a negative offset
authorGlenn Randers-Pehrson <glennrp@gmail.com>
Sat, 19 Aug 2017 15:44:27 +0000 (11:44 -0400)
committerGlenn Randers-Pehrson <glennrp@gmail.com>
Sat, 19 Aug 2017 15:44:27 +0000 (11:44 -0400)
TO DO: handle short months properly.

ChangeLog
coders/png.c

index 7befd754c4ead0a53aa7b9ef33291e1aa2086840..8d9c4ecc4efe90b39cb968bc8fdb54d909b60b47 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-08-18  7.0.6-9 Glenn Randers-Pehrson <glennrp@image...>
+  * Fixed bug with writing tIME chunk when timezone has a negative offset
+  (reference: https://github.com/ImageMagick/ImageMagick/issues/685)
+
 2017-08-18  7.0.6-8 Cristy  <quetzlzacatenango@image...>
   * Release ImageMagick version 7.0.6-8, GIT revision 20838:e2eb79427:20170818.
 
index 0c1e0838fc6a6dc03c16001fdadb273b650a573a..931a3886090fed274a962e9167dea8e06c470b2c 100644 (file)
@@ -8154,7 +8154,9 @@ static void write_tIME_chunk(Image *image,png_struct *ping,png_info *info,
     minute,
     month,
     second,
-    year,
+    year;
+
+  int
     addhours=0,
     addminutes=0;
 
@@ -8174,16 +8176,40 @@ static void write_tIME_chunk(Image *image,png_struct *ping,png_info *info,
   addminutes=0;     
   ret=sscanf(timestamp,"%d-%d-%dT%d:%d:%d%d:%d",&year,&month,&day,&hour,
       &minute, &second, &addhours, &addminutes);
+    LogMagickEvent(CoderEvent,GetMagickModule(),
+      "   Date format specified for png:tIME=%60s" ,timestamp);
+    LogMagickEvent(CoderEvent,GetMagickModule(),
+      "      ret=%d,y=%d, m=%d, d=%d, h=%d, m=%d, s=%d, ah=%d, as=%d",
+      ret,year,month,day,hour,minute,second,addhours,addminutes);
   if (ret < 6)
   {
+    LogMagickEvent(CoderEvent,GetMagickModule(),
+      "      Invalid date, ret=%d",ret);
     (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
-      "Invalid date format specified for png:tIME","`%s'",
-      image->filename);
+      "Invalid date format specified for png:tIME","`%s' (ret=%d)",
+      image->filename,ret);
     return;
   }
   ptime.year=(png_uint_16) year;
   ptime.month=(png_byte) month;
   ptime.day=(png_byte) day;
+  if (addhours < 0)
+  {
+    addhours+=24;
+    ptime.hour=(png_byte) hour+addhours;
+    ptime.day--;
+    if (ptime.day == 0)
+    {
+      /* wrong for short months */
+      ptime.month--;
+      ptime.day=31;
+    }
+    if (ptime.month == 0)
+    {
+      ptime.month++;
+      ptime.year--;
+    }
+  }
   ptime.hour=(png_byte) hour+addhours;
   ptime.minute=(png_byte) minute+addminutes;
   ptime.second=(png_byte) second;
@@ -8197,6 +8223,11 @@ static void write_tIME_chunk(Image *image,png_struct *ping,png_info *info,
      ptime.day ++;
      ptime.hour -=24;
   }
+  if (ptime.hour < 0)
+  {
+     ptime.day --;
+     ptime.hour +=24;
+  }
   /* To do: fix this for leap years */
   if (ptime.day > 31 || (ptime.month == 2 && ptime.day > 28) ||
       ((ptime.month == 4 || ptime.month == 6 || ptime.month == 9 ||
@@ -8210,6 +8241,11 @@ static void write_tIME_chunk(Image *image,png_struct *ping,png_info *info,
      ptime.year++;
      ptime.month=1;
   }
+
+  LogMagickEvent(CoderEvent,GetMagickModule(),
+      "      png_set_tIME: y=%d, m=%d, d=%d, h=%d, m=%d, s=%d, ah=%d, am=%d",
+      ptime.year, ptime.month, ptime.day, ptime.hour, ptime.minute,
+      ptime.second, addhours, addminutes);
   png_set_tIME(ping,info,&ptime);
 }
 #endif