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
This commit is contained in:
John Blackbourn 2017-10-24 23:10:37 +00:00
parent 18a231bad6
commit 49b7cb458f
1 changed files with 9 additions and 2 deletions

View File

@ -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) )