PNG 'tIME' chunk not in UTC

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
geitda
Posts: 7
Joined: 2015-06-26T12:27:40-07:00
Authentication code: 6789

PNG 'tIME' chunk not in UTC

Post by geitda » 2017-08-03T09:52:55-07:00

Version: ImageMagick 7.0.6-5 Q16 x64 2017-08-03 (DLL)
Operating System: Windows 7 64-bit
Command:

Code: Select all

convert -size 1x1 xc:white a.png
What it does: populates the 'tIME' chunk without taking the computer's timezone offset into account, i.e. local time (UTC-04:00) is 12:01:23, and it populates 12:01:23. I checked this with "identify -verbose a.png" and it returns "png:tIME: 2017-08-03T12:01:23Z" (with the 'Z' at the end meaning UTC) and a quick check in a hex editor shows "07 E1 08 03 0C 01 17" which is 2017(two bytes, big endian), 8, 3, 12, 1, 23 for year, month, day, hour, minute, second.
What it should do: populate the 'tIME' chunk with the correct modify time, i.e. UTC time. See RFC 2083, section 4.2.8: "Universal Time (UTC, also called GMT) should be specified rather than local time." So this should populate 16:01:23
The 'date:create' and 'date:modify' 'tEXt' chunks are already correct: "identify -verbsoe a.png" shows "date:modify: 2017-08-03T12:01:23-04:00" with the '-04:00' at the end which is indeed correct. This error is only with the 'tIME' chunk. Again, the 'tEXt' chunks are fine, so the thread "create:date and modify:date are always set" is not relevant.

User avatar
glennrp
Posts: 1163
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: PNG 'tIME' chunk not in UTC

Post by glennrp » 2017-08-03T16:46:51-07:00

coders/png.c, line 8178, write_tIME_chunk(), gets the time from

Code: Select all

time_t ttime;
time(&ttime);
On my Ubuntu platform, "man 2 time" claims that it returns time in UTC.
However, I confirm that a PNG image created at 19:54 EDT gets a tIME chunk with 19:54 UTC.

The date:create property comes from MagickCore/blob.c:

Code: Select all

blob_info->properties.st_mtime=time((time_t *) NULL);
Not sure why they are different, but I could revise png.c to use the
date:create property instead of generating a new timestamp.

User avatar
glennrp
Posts: 1163
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: PNG 'tIME' chunk not in UTC

Post by glennrp » 2017-08-03T19:16:20-07:00

Fixed. I added "addhours" and "addminutes" to the scan of "date", and added
that to the existing hours and minutes. Needs more work to handle February
28 on leap years, though.

Post Reply