From 295c896a502167c6322f1ec4740723857a7f9847 Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Sat, 19 Aug 2017 11:44:27 -0400 Subject: [PATCH] Fixed bug with writing tIME chunk when timezone has a negative offset TO DO: handle short months properly. --- ChangeLog | 4 ++++ coders/png.c | 42 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7befd754c..8d9c4ecc4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-08-18 7.0.6-9 Glenn Randers-Pehrson + * 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 * Release ImageMagick version 7.0.6-8, GIT revision 20838:e2eb79427:20170818. diff --git a/coders/png.c b/coders/png.c index 0c1e0838f..931a38860 100644 --- a/coders/png.c +++ b/coders/png.c @@ -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 -- 2.40.0