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.


git-svn-id: https://develop.svn.wordpress.org/trunk@44438 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe McGill
2019-01-07 20:47:56 +00:00
parent c7fb3b36ea
commit 94c8a5d994
2 changed files with 72 additions and 2 deletions

View File

@@ -2569,10 +2569,31 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
* This means that common mismatches are forgiven: application/vnd.apple.numbers is often misidentified as application/zip,
* and some media files are commonly named with the wrong extension (.mov instead of .mp4)
*/
if ( substr( $real_mime, 0, strcspn( $real_mime, '/' ) ) !== substr( $type, 0, strcspn( $type, '/' ) ) ) {
$type = $ext = false;
}
} elseif ( 'text/plain' === $real_mime ) {
// A few common file types are occasionally detected as text/plain; allow those.
if ( ! in_array( $type, array(
'text/plain',
'text/csv',
'text/richtext',
'text/tsv',
'text/vtt',
) )
) {
$type = $ext = false;
}
} elseif( 'text/rtf' === $real_mime ) {
// Special casing for RTF files.
if ( ! in_array( $type, array(
'text/rtf',
'text/plain',
'application/rtf',
) )
) {
$type = $ext = false;
}
} else {
if ( $type !== $real_mime ) {
/*