Make WordPress Core

Changeset 44438 for trunk


Ignore:
Timestamp:
01/07/2019 08:47:56 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.

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

Location:
trunk
Files:
2 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                        }
  • trunk/tests/phpunit/tests/functions.php

    r44292 r44438  
    12311231
    12321232        /**
    1233          * Data profider for test_wp_get_image_mime();
     1233         * Data provider for test_wp_get_image_mime();
    12341234         */
    12351235        public function _wp_get_image_mime() {
    … …  
    13341334                                        'ext'             => false,
    13351335                                        'type'            => false,
     1336                                        'proper_filename' => false,
     1337                                ),
     1338                        ),
     1339                        // Non-image file not allowed even if it's named like one.
     1340                        array(
     1341                                DIR_TESTDATA . '/export/crazy-cdata.xml',
     1342                                'crazy-cdata.jpg',
     1343                                array(
     1344                                        'ext' => false,
     1345                                        'type' => false,
     1346                                        'proper_filename' => false,
     1347                                ),
     1348                        ),
     1349                        // Non-image file not allowed if it's named like something else.
     1350                        array(
     1351                                DIR_TESTDATA . '/export/crazy-cdata.xml',
     1352                                'crazy-cdata.doc',
     1353                                array(
     1354                                        'ext' => false,
     1355                                        'type' => false,
     1356                                        'proper_filename' => false,
     1357                                ),
     1358                        ),
     1359                        // Assorted text/* sample files
     1360                        array(
     1361                                DIR_TESTDATA . '/uploads/test.vtt',
     1362                                'test.vtt',
     1363                                array(
     1364                                        'ext' => 'vtt',
     1365                                        'type' => 'text/vtt',
     1366                                        'proper_filename' => false,
     1367                                ),
     1368                        ),
     1369                        array(
     1370                                DIR_TESTDATA . '/uploads/test.csv',
     1371                                'test.csv',
     1372                                array(
     1373                                        'ext' => 'csv',
     1374                                        'type' => 'text/csv',
     1375                                        'proper_filename' => false,
     1376                                ),
     1377                        ),
     1378                        // RTF files.
     1379                        array(
     1380                                DIR_TESTDATA . '/uploads/test.rtf',
     1381                                'test.rtf',
     1382                                array(
     1383                                        'ext' => 'rtf',
     1384                                        'type' => 'application/rtf',
    13361385                                        'proper_filename' => false,
    13371386                                ),
Note: See TracChangeset for help on using the changeset viewer.