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.
crash if invalid modifed time in image file, IM 6.4.6
Re: crash if invalid modifed time in image file, IM 6.4.6
We can reproduce the problem you posted and have a patch. Look for it in the next point release of ImageMagick within a week or two.
Can you post a URL to your TIFF image. We would like to download it and verify our patch works.
Can you post a URL to your TIFF image. We would like to download it and verify our patch works.
Re: crash if invalid modifed time in image file, IM 6.4.6
Thanks for the quick response.
Our client will not allow use of their file for testing. If we can recreate the issue on an in-house file, I will let you know, otherwise, when we get the patch, I will test using the client's file and let you know the result.
Our client will not allow use of their file for testing. If we can recreate the issue on an in-house file, I will let you know, otherwise, when we get the patch, I will test using the client's file and let you know the result.
Re: crash if invalid modifed time in image file, IM 6.4.6
Grab ImageMagick 6.5.4-7 from ftp://magick.imagemagick.org/pub/ImageMagick/beta and let us know if that fixes the problem.
Re: crash if invalid modifed time in image file, IM 6.4.6
Using the ImageMagick-6.5.4-7-windows.zip, there was a build error when I built the windows project (VisualStaticMT.dsw == static MT libs):
[mybuildpath]\ImageMagick-6.5.4\coders\mpc.c(575) : error C2143: syntax error : missing ')' before '{'
The good news is, after fixing that minor error, the patch fixes the issue of the invalid modification date.
Thanks.
[mybuildpath]\ImageMagick-6.5.4\coders\mpc.c(575) : error C2143: syntax error : missing ')' before '{'
The good news is, after fixing that minor error, the patch fixes the issue of the invalid modification date.
Thanks.