From 64e8c4952a80f19c498428188c97e3a5d0f5841a Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 19 Sep 2017 14:35:09 +0000 Subject: [PATCH] Filesystem API: Ensure filenames are valid before attempting to unzip them to ensure malformed file paths don't cause issues. git-svn-id: https://develop.svn.wordpress.org/trunk@41457 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/file.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index f81444e0dd..05bfde46a4 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -666,6 +666,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 ) ) { @@ -826,6 +830,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'] ); }