diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 68a77b292e..c2464f26b8 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -652,12 +652,23 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) { function _unzip_file_pclzip($file, $to, $needed_dirs = array()) { global $wp_filesystem; + // See #15789 - PclZip uses string functions on binary data, If it's overloaded with Multibyte safe functions the results are incorrect. + if ( ini_get('mbstring.func_overload') && function_exists('mb_internal_encoding') ) { + $previous_encoding = mb_internal_encoding(); + mb_internal_encoding('ISO-8859-1'); + } + require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php'); $archive = new PclZip($file); + $archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING); + + if ( isset($previous_encoding) ) + mb_internal_encoding($previous_encoding); + // Is the archive valid? - if ( false == ($archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING)) ) + if ( false === $archive_files ) return new WP_Error('incompatible_archive', __('Incompatible Archive.'), $archive->errorInfo(true)); if ( 0 == count($archive_files) )