[wp-trac] [WordPress Trac] #52531: Unable to upload .ico with PHP 7.4

WordPress Trac noreply at wordpress.org
Mon Feb 15 16:41:43 UTC 2021


#52531: Unable to upload .ico with PHP 7.4
--------------------------+-----------------------------
 Reporter:  lpointet      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.6.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hello,

 I found the following related ticket: #11824
 You can find attached an example file.

 On PHP 7.3.21 libmagic is shown as 533 in phpinfo under "fileinfo"
 section.
 On PHP 7.4.9 libmagic is shown as 537 in phpinfo under "fileinfo" section.

 I tried to upload the same file as an admin on a fresh WP install on both
 versions on PHP, and it works with 7.3 while it doesn't with 7.4.

 The error is "Sorry, this file type is not permitted for security
 reasons.".

 What I found is that `finfo_file` function returns either "image/x-icon"
 or "image/vnd.microsoft.icon" depending on the PHP version I'm using.
 In the first case, this will be allowed because it matches WP's internal
 mime types array. But in the second case, it will simply return an invalid
 type error (empty `$type` and `$ext` variables).

 I used the following workaround:
 {{{#!php
 <?php
 function tmp_wp_check_filetype_and_ext( $values, $file, $filename, $mimes,
 $real_mime ) {
         if( ! $values['ext'] && ! $values['type'] && $real_mime ===
 'image/vnd.microsoft.icon' && preg_match( '!\.(ico)$!i', $filename, $ext )
 ) {
                 $values['ext'] = $ext[1];
                 $values['type'] = 'image/x-icon';
         }

         return $values;
 }
 add_filter( 'wp_check_filetype_and_ext', 'tmp_wp_check_filetype_and_ext',
 10, 5 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52531>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list