WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/25/2017 04:07:25 PM (3 years ago)
Author:
joemcgill
Message:

Media: Reduce failing uploads following 4.7.1.

[39831] introduced more strict MIME type checking for uploads, which
resulted in unintetionally blocking several filetypes that were
previously valid. This change uses a more targeted approach to MIME
validation to restore previous behavior for most types.

Props blobfolio, iandunn, ipstenu, markoheijnen, xknown, joemcgill.
Fixes #39550, #39552.

File:
1 edited

Legend:

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

    r40039 r40124  
    22702270    }
    22712271
     2272    $real_mime = false;
     2273
    22722274    // Validate image types.
    22732275    if ( $type && 0 === strpos( $type, 'image/' ) ) {
     
    22762278        $real_mime = wp_get_image_mime( $file );
    22772279
    2278         if ( ! $real_mime ) {
    2279             $type = $ext = false;
    2280         } elseif ( $real_mime != $type ) {
     2280        if ( $real_mime && $real_mime != $type ) {
    22812281            /**
    22822282             * Filters the list mapping image mime types to their respective extensions.
     
    23092309                $type = $wp_filetype['type'];
    23102310            } else {
    2311                 $type = $ext = false;
     2311                // Reset $real_mime and try validating again.
     2312                $real_mime = false;
    23122313            }
    23132314        }
    2314     } elseif ( function_exists( 'finfo_file' ) ) {
    2315         // Use finfo_file if available to validate non-image files.
     2315    }
     2316
     2317    // Validate files that didn't get validated during previous checks.
     2318    if ( $type && ! $real_mime && extension_loaded( 'fileinfo' ) ) {
    23162319        $finfo = finfo_open( FILEINFO_MIME_TYPE );
    23172320        $real_mime = finfo_file( $finfo, $file );
    23182321        finfo_close( $finfo );
    23192322
    2320         // If the extension does not match the file's real type, return false.
    2321         if ( $real_mime !== $type ) {
    2322             $type = $ext = false;
     2323        /*
     2324         * If $real_mime doesn't match what we're expecting, we need to do some extra
     2325         * vetting of application mime types to make sure this type of file is allowed.
     2326         * Other mime types are assumed to be safe, but should be considered unverified.
     2327         */
     2328        if ( $real_mime && ( $real_mime !== $type ) && ( 0 === strpos( $real_mime, 'application' ) ) ) {
     2329            $allowed = get_allowed_mime_types();
     2330
     2331            if ( ! in_array( $real_mime, $allowed ) ) {
     2332                $type = $ext = false;
     2333            }
    23232334        }
    23242335    }
Note: See TracChangeset for help on using the changeset viewer.