Make WordPress Core


Ignore:
Timestamp:
01/07/2019 10:22:03 PM (8 years 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.

Merges [44438], [44439], [44441], and [44442] to the 4.9 branch.

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

Location:
branches/5.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0

  • branches/5.0/src/wp-includes/functions.php

    r44407 r44443  
    23742374                         * and some media files are commonly named with the wrong extension (.mov instead of .mp4)
    23752375                         */
    2376 
    23772376                        if ( substr( $real_mime, 0, strcspn( $real_mime, '/' ) ) !== substr( $type, 0, strcspn( $type, '/' ) ) ) {
     2377                                $type = $ext = false;
     2378                        }
     2379                } elseif ( 'text/plain' === $real_mime ) {
     2380                        // A few common file types are occasionally detected as text/plain; allow those.
     2381                        if ( ! in_array(
     2382                                $type,
     2383                                array(
     2384                                        'text/plain',
     2385                                        'text/csv',
     2386                                        'text/richtext',
     2387                                        'text/tsv',
     2388                                        'text/vtt',
     2389                                )
     2390                        )
     2391                        ) {
     2392                                $type = $ext = false;
     2393                        }
     2394                } elseif ( 'text/rtf' === $real_mime ) {
     2395                        // Special casing for RTF files.
     2396                        if ( ! in_array(
     2397                                $type,
     2398                                array(
     2399                                        'text/rtf',
     2400                                        'text/plain',
     2401                                        'application/rtf',
     2402                                )
     2403                        )
     2404                        ) {
    23782405                                $type = $ext = false;
    23792406                        }
Note: See TracChangeset for help on using the changeset viewer.