crash if invalid modifed time in image file, IM 6.4.6
Posted: 2009-07-28T12:47:37-07:00
We have a tif file, generated on a Mac, whose modified time is invalid in Windows. We are using ImageMagick to extract a jpg thumbnail from the tif.
In a windows folder, if I right click the file name and check out its properties, all are OK except modified, which is reporte thus:
Modified: Tuesday, January 02, 1601, 3:12:05 AM
ImageMagick does not extract an image because ImageMagick fails in ../magick/constitute.c at:
MagickExport Image *ReadImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
...
// this call throws an exception
(void) FormatMagickTime(GetBlobProperties(next)->st_mtime,MaxTextExtent,
timestamp);
...
}
The call fails because st_mtime = -1, and FormatMagickTime method does not check for -1 (or any negative value) and do something reasonable, it just throws an exception on the use of the variable local_time (is NULL) in the following:
MagickExport long FormatMagickTime(const time_t time,const size_t length,
char *timestamp)
{
long
count;
struct tm
local_time,
utc_time;
time_t
timezone;
assert(timestamp != (char *) NULL);
local_time=(*localtime(&time));
utc_time=(*gmtime(&time));
timezone=(time_t) ((local_time.tm_min-utc_time.tm_min)/60+local_time.tm_hour-
utc_time.tm_hour+24*((local_time.tm_year-utc_time.tm_year) != 0 ?
(local_time.tm_year-utc_time.tm_year) : (local_time.tm_yday-
utc_time.tm_yday)));
count=FormatMagickString(timestamp,length,
"%04d-%02d-%02dT%02d:%02d:%02d%+03ld:00",local_time.tm_year+1900,
local_time.tm_mon+1,local_time.tm_mday,local_time.tm_hour,local_time.tm_min,
local_time.tm_sec,(long) timezone);
return(count);
}
Note, ImageMagick Display (ImageMagick 6.3.5 Q16) does not work with the file; it just crashes. I downloaded IM 6.3.5 source and it is essentially the same as 6.4.6 in this method.
All my other image viewers open the image content, as presumably they do not care about the modified time of the file. I tested with IrfanView, PhotoshopCS2, Windows default image viewer, and MS Paint.
From our point of view, it would be reasonable for IM to set any invalid (negative) file time to 0 and muddle through; we can report the file time problem to our client in later processing of the file.
Thanks.
In a windows folder, if I right click the file name and check out its properties, all are OK except modified, which is reporte thus:
Modified: Tuesday, January 02, 1601, 3:12:05 AM
ImageMagick does not extract an image because ImageMagick fails in ../magick/constitute.c at:
MagickExport Image *ReadImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
...
// this call throws an exception
(void) FormatMagickTime(GetBlobProperties(next)->st_mtime,MaxTextExtent,
timestamp);
...
}
The call fails because st_mtime = -1, and FormatMagickTime method does not check for -1 (or any negative value) and do something reasonable, it just throws an exception on the use of the variable local_time (is NULL) in the following:
MagickExport long FormatMagickTime(const time_t time,const size_t length,
char *timestamp)
{
long
count;
struct tm
local_time,
utc_time;
time_t
timezone;
assert(timestamp != (char *) NULL);
local_time=(*localtime(&time));
utc_time=(*gmtime(&time));
timezone=(time_t) ((local_time.tm_min-utc_time.tm_min)/60+local_time.tm_hour-
utc_time.tm_hour+24*((local_time.tm_year-utc_time.tm_year) != 0 ?
(local_time.tm_year-utc_time.tm_year) : (local_time.tm_yday-
utc_time.tm_yday)));
count=FormatMagickString(timestamp,length,
"%04d-%02d-%02dT%02d:%02d:%02d%+03ld:00",local_time.tm_year+1900,
local_time.tm_mon+1,local_time.tm_mday,local_time.tm_hour,local_time.tm_min,
local_time.tm_sec,(long) timezone);
return(count);
}
Note, ImageMagick Display (ImageMagick 6.3.5 Q16) does not work with the file; it just crashes. I downloaded IM 6.3.5 source and it is essentially the same as 6.4.6 in this method.
All my other image viewers open the image content, as presumably they do not care about the modified time of the file. I tested with IrfanView, PhotoshopCS2, Windows default image viewer, and MS Paint.
From our point of view, it would be reasonable for IM to set any invalid (negative) file time to 0 and muddle through; we can report the file time problem to our client in later processing of the file.
Thanks.