WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/07/2019 08:47:56 PM (7 months ago)
Author:
joemcgill
Message:

Upload: Fix upload failures of common text file types.

This adds some special case handling in 'wp_check_filetype_and_ext()' that prevents some common file types from being blocked based on mismatched MIME checks, which were made more strict in WordPress 5.0.1.

Props Kloon, birgire, tellyworth, joemcgill.
See #45615.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r44406 r44438  
    25702570             * and some media files are commonly named with the wrong extension (.mov instead of .mp4)
    25712571             */
    2572 
    25732572            if ( substr( $real_mime, 0, strcspn( $real_mime, '/' ) ) !== substr( $type, 0, strcspn( $type, '/' ) ) ) {
     2573                $type = $ext = false;
     2574            }
     2575        } elseif ( 'text/plain' === $real_mime ) {
     2576            // A few common file types are occasionally detected as text/plain; allow those.
     2577            if ( ! in_array( $type, array(
     2578                    'text/plain',
     2579                    'text/csv',
     2580                    'text/richtext',
     2581                    'text/tsv',
     2582                    'text/vtt',
     2583                ) )
     2584            ) {
     2585                $type = $ext = false;
     2586            }
     2587        } elseif( 'text/rtf' === $real_mime ) {
     2588            // Special casing for RTF files.
     2589            if ( ! in_array( $type, array(
     2590                    'text/rtf',
     2591                    'text/plain',
     2592                    'application/rtf',
     2593                ) )
     2594            ) {
    25742595                $type = $ext = false;
    25752596            }
Note: See TracChangeset for help on using the changeset viewer.