From 4c0c42db178739857071174e045afbbb887a3203 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 13 Dec 2025 20:12:32 +0000 Subject: [PATCH] Filesystem API: Pass correct `$file` value to `pre_unzip_file` and `unzip_file` filters. This commit ensures that the original `$file` argument passed to the function is not unintentionally overwritten by the use of the same variable name in two `foreach` loops. Follow-up to [56689]. Props sanchothefat, westonruter, mukesh27, SergeyBiryukov. Fixes #64398. Built from https://develop.svn.wordpress.org/trunk@61374 git-svn-id: http://core.svn.wordpress.org/trunk@60686 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/file.php | 22 +++++++++++----------- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 0658662126..948cb8e88e 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -1896,14 +1896,14 @@ function _unzip_file_pclzip( $file, $to, $needed_dirs = array() ) { $uncompressed_size = 0; // Determine any children directories needed (From within the archive). - foreach ( $archive_files as $file ) { - if ( str_starts_with( $file['filename'], '__MACOSX/' ) ) { // Skip the OS X-created __MACOSX directory. + foreach ( $archive_files as $archive_file ) { + if ( str_starts_with( $archive_file['filename'], '__MACOSX/' ) ) { // Skip the OS X-created __MACOSX directory. continue; } - $uncompressed_size += $file['size']; + $uncompressed_size += $archive_file['size']; - $needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname( $file['filename'] ) ); + $needed_dirs[] = $to . untrailingslashit( $archive_file['folder'] ? $archive_file['filename'] : dirname( $archive_file['filename'] ) ); } // Enough space to unzip the file and copy its contents, with a 10% buffer. @@ -1967,22 +1967,22 @@ function _unzip_file_pclzip( $file, $to, $needed_dirs = array() ) { } // Extract the files from the zip. - foreach ( $archive_files as $file ) { - if ( $file['folder'] ) { + foreach ( $archive_files as $archive_file ) { + if ( $archive_file['folder'] ) { continue; } - - if ( str_starts_with( $file['filename'], '__MACOSX/' ) ) { // Don't extract the OS X-created __MACOSX directory files. + + if ( str_starts_with( $archive_file['filename'], '__MACOSX/' ) ) { // Don't extract the OS X-created __MACOSX directory files. continue; } // Don't extract invalid files: - if ( 0 !== validate_file( $file['filename'] ) ) { + if ( 0 !== validate_file( $archive_file['filename'] ) ) { continue; } - if ( ! $wp_filesystem->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE ) ) { - return new WP_Error( 'copy_failed_pclzip', __( 'Could not copy file.' ), $file['filename'] ); + if ( ! $wp_filesystem->put_contents( $to . $archive_file['filename'], $archive_file['content'], FS_CHMOD_FILE ) ) { + return new WP_Error( 'copy_failed_pclzip', __( 'Could not copy file.' ), $archive_file['filename'] ); } } diff --git a/wp-includes/version.php b/wp-includes/version.php index e78f18704f..5558d6fd4a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '7.0-alpha-61373'; +$wp_version = '7.0-alpha-61374'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.