From 3e77adc6196383091254fbc562a4b2ecc39e71ee Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 19 Sep 2017 14:37:33 +0000 Subject: [PATCH] Filesystem API: Ensure filenames are valid before attempting to unzip them to ensure malformed file paths don't cause issues. Merges [41457] to the 4.8 branch. Built from https://develop.svn.wordpress.org/branches/4.8@41458 git-svn-id: http://core.svn.wordpress.org/branches/4.8@41291 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/file.php | 8 ++++++++ wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index b1f447ea62..3d1a07aaaf 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -647,6 +647,10 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) { if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory continue; + if ( 0 !== validate_file( $info['name'] ) ) { + return new WP_Error( 'invalid_file_ziparchive', __( 'Could not extract file from archive.' ), $info['name'] ); + } + $uncompressed_size += $info['size']; if ( '/' === substr( $info['name'], -1 ) ) { @@ -807,6 +811,10 @@ function _unzip_file_pclzip($file, $to, $needed_dirs = array()) { if ( '__MACOSX/' === substr($file['filename'], 0, 9) ) // Don't extract the OS X-created __MACOSX directory files continue; + if ( 0 !== validate_file( $file['filename'] ) ) { + return new WP_Error( 'invalid_file_pclzip', __( 'Could not extract file from archive.' ), $file['filename'] ); + } + 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'] ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 4654dd3f84..ec443a601a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8.2-alpha-41450'; +$wp_version = '4.8.2-alpha-41458'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.