diff options
Diffstat (limited to 'includes/MimeMagic.php')
-rw-r--r-- | includes/MimeMagic.php | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php index 5be0ee602954..31f57d0e7d11 100644 --- a/includes/MimeMagic.php +++ b/includes/MimeMagic.php @@ -304,6 +304,27 @@ class MimeMagic { return in_array( $mime, $types ); } + /** + * Returns true if the extension represents a type which can + * be reliably detected from its content. Use this to determine + * whether strict content checks should be applied to reject + * invalid uploads; if we can't identify the type we won't + * be able to say if it's invalid. + * + * @todo Be more accurate when using fancy mime detector plugins; + * right now this is the bare minimum getimagesize() list. + * @return bool + */ + function isRecognizableExtension( $extension ) { + static $types = array( + 'gif', 'jpeg', 'jpg', 'png', 'swf', 'psd', + 'bmp', 'tiff', 'tif', 'jpc', 'jp2', + 'jpx', 'jb2', 'swc', 'iff', 'wbmp', + 'xbm' + ); + return in_array( strtolower( $extension ), $types ); + } + /** mime type detection. This uses detectMimeType to detect the mim type of the file, * but applies additional checks to determine some well known file formats that may be missed @@ -318,14 +339,21 @@ class MimeMagic { $fname = 'MimeMagic::guessMimeType'; $mime= $this->detectMimeType($file,$useExt); - if (strpos($mime,"text/")===0 || - $mime==="application/xml") { + // Read a chunk of the file + $f = fopen( $file, "rt" ); + if( !$f ) return "unknown/unknown"; + $head = fread( $f, 1024 ); + fclose( $f ); + + $sub4 = substr( $head, 0, 4 ); + if ( $sub4 == "\x01\x00\x09\x00" || $sub4 == "\xd7\xcd\xc6\x9a" ) { + // WMF kill kill kill + // Note that WMF may have a bare header, no magic number. + // The former of the above two checks is theoretically prone to false positives + $mime = "application/x-msmetafile"; + } - // Read a chunk of the file - $f = fopen( $file, "rt" ); - if( !$f ) return "unknown/unknown"; - $head = fread( $f, 1024 ); - fclose( $f ); + if (strpos($mime,"text/")===0 || $mime==="application/xml") { $xml_type= NULL; $script_type= NULL; |