From e52423e43563c2a952160b2fc0f92aa3ab9c89f9 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 18 Oct 2024 23:37:20 +0000 Subject: [PATCH] Upgrade/Install: Return WP_Error when source files cannot be found. Fixes a fatal error in `array_keys()` (PHP 8.0+) as `$wp_filesystem->dirlist()` will return `false` when the source directory doesn't exist or becomes unreadable for some reason. Props: verygoode, lifelightweb, da5f656f, costdev, afragen, azaozz Fixes #61114 Built from https://develop.svn.wordpress.org/trunk@59257 git-svn-id: http://core.svn.wordpress.org/trunk@58649 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-upgrader.php | 17 +++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 67996aef3f..a9784682eb 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -204,6 +204,7 @@ class WP_Upgrader { $this->strings['mkdir_failed'] = __( 'Could not create directory.' ); $this->strings['incompatible_archive'] = __( 'The package could not be installed.' ); $this->strings['files_not_writable'] = __( 'The update cannot be installed because some files could not be copied. This is usually due to inconsistent file permissions.' ); + $this->strings['dir_not_readable'] = __( 'A directory could not be read.' ); $this->strings['maintenance_start'] = __( 'Enabling Maintenance mode…' ); $this->strings['maintenance_end'] = __( 'Disabling Maintenance mode…' ); @@ -558,7 +559,13 @@ class WP_Upgrader { $remote_source = $args['source']; $local_destination = $destination; - $source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) ); + $dirlist = $wp_filesystem->dirlist( $remote_source ); + + if ( false === $dirlist ) { + return new WP_Error( 'source_read_failed', $this->strings['fs_error'], $this->strings['dir_not_readable'] ); + } + + $source_files = array_keys( $dirlist ); $remote_destination = $wp_filesystem->find_folder( $local_destination ); // Locate which directory to copy to the new folder. This is based on the actual folder holding the files. @@ -605,7 +612,13 @@ class WP_Upgrader { // Has the source location changed? If so, we need a new source_files list. if ( $source !== $remote_source ) { - $source_files = array_keys( $wp_filesystem->dirlist( $source ) ); + $dirlist = $wp_filesystem->dirlist( $source ); + + if ( false === $dirlist ) { + return new WP_Error( 'new_source_read_failed', $this->strings['fs_error'], $this->strings['dir_not_readable'] ); + } + + $source_files = array_keys( $dirlist ); } /* diff --git a/wp-includes/version.php b/wp-includes/version.php index dbc1475c48..22ce0efb45 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.7-beta3-59256'; +$wp_version = '6.7-beta3-59257'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.