From 49b7cb458f4e6639ebae3cfcb26b20fb4f7c2672 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 24 Oct 2017 23:10:37 +0000 Subject: [PATCH] Filesystem API: Don't immediately return an error for invalid file names contained within a Zip while it's being extracted. This allows the extraction of the rest of the valid files within the archive to continue. See #42016 git-svn-id: https://develop.svn.wordpress.org/trunk@42010 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/file.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index 858f828185..416433e5a5 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -1119,8 +1119,9 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) { if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory continue; + // Don't extract invalid files: if ( 0 !== validate_file( $info['name'] ) ) { - return new WP_Error( 'invalid_file_ziparchive', __( 'Could not extract file from archive.' ), $info['name'] ); + continue; } $uncompressed_size += $info['size']; @@ -1180,6 +1181,11 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) { if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Don't extract the OS X-created __MACOSX directory files continue; + // Don't extract invalid files: + if ( 0 !== validate_file( $info['name'] ) ) { + continue; + } + $contents = $z->getFromIndex($i); if ( false === $contents ) return new WP_Error( 'extract_failed_ziparchive', __( 'Could not extract file from archive.' ), $info['name'] ); @@ -1283,8 +1289,9 @@ 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; + // Don't extract invalid files: if ( 0 !== validate_file( $file['filename'] ) ) { - return new WP_Error( 'invalid_file_pclzip', __( 'Could not extract file from archive.' ), $file['filename'] ); + continue; } if ( ! $wp_filesystem->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) )