Bug #23348
closedArray returned by t3lib_stdGraphic::imageMagickIdentify() contains useless value for file extension
100%
Description
The current version of the method t3lib_stdGraphic::imageMagickIdentify() does what it's supposed to do according to documentation.
Nevertheless the returned value for "file extension" is of no real use and ignores ImageMagick's identifying capabilities by returning a ereg result on the originally passed filename instead of extracting the actual file type determined by ImageMagick.
In other words - the documentation states, that imageMagickIdentify() "Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename. Using ImageMagick".
The point here is, that [2] is filled with $reg0 which is created via ereg('([^\.]*)$',$imagefile,$reg);
While this works for images which provide a file extension as part of their filename, it obviously fails on files missing it.
This is the case when you try to identify an image e.g. before copying it to your uploads-folder in order to ensure it's a valid image file and thus run the check on a temporary file (which does not have an extension).
This issue could easily be solved by simply using the info ImageMagick provides by itself instead of relying on the filename.
A proposed patch is included with the report and should be checked for use.
The patch basically includes only two changes (line numbers according to r8200):
1. remove call to ereg on line 2672
2. change return array to use $splitinfo1 instead of $reg0.
The second change bases on a reliable assumtion, because ImageMagick's return string always starts according to the following syntax:
"fullFileName fileType imageDimension moreInfo_0 moreInfo_1 moreInfo_2 moreInfo_n"
e.g. rose.jpg JPEG 640x480 DirectClass 87kb 0.050u 0:01
This patch would make sure that the file type is always returned no matter what the filename is as long as the identification succeeds.
With kind regards,
Grigori Prokhorov
(issue imported from #M15347)
Files