From e0ace80488f2f6d849d5bbed577db1fdd492d331 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 16 Dec 2019 23:23:06 +0000 Subject: [PATCH] Upload: - Fix PHP warnings in `wp_unique_filename()` when the destination directory is unreadable. - Run the final name collision test only for files that are saved to the uploads directory. - Update the unit tests to match. Props eden159, audrasjb, azaozz. Fixes #48960 for trunk. Built from https://develop.svn.wordpress.org/trunk@46965 git-svn-id: http://core.svn.wordpress.org/trunk@46765 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 12 +++++++++--- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 500aa35a0e..4cc62be66d 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -2472,11 +2472,17 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) // Prevent collisions with existing file names that contain dimension-like strings // (whether they are subsizes or originals uploaded prior to #42437). + $upload_dir = wp_get_upload_dir(); // The (resized) image files would have name and extension, and will be in the uploads dir. - if ( @is_dir( $dir ) && $name && $ext ) { - // List of all files and directories contained in $dir (with the "dot" files removed). - $files = array_diff( scandir( $dir ), array( '.', '..' ) ); + if ( $name && $ext && @is_dir( $dir ) && false !== strpos( $dir, $upload_dir['basedir'] ) ) { + // List of all files and directories contained in $dir. + $files = @scandir( $dir ); + + if ( ! empty( $files ) ) { + // Remove "dot" dirs. + $files = array_diff( $files, array( '.', '..' ) ); + } if ( ! empty( $files ) ) { while ( _wp_check_existing_file_names( $filename, $files ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 6b69c4910c..86b812d71d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.4-alpha-46964'; +$wp_version = '5.4-alpha-46965'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.