Ticket #25259: 25259.diff
File 25259.diff, 4.4 KB (added by , 11 years ago) |
---|
-
src/wp-includes/class-http.php
166 166 // Construct Cookie: header if any cookies are set 167 167 WP_Http::buildCookieHeader( $r ); 168 168 169 // Avoid issues where mbstring.func_overload is enabled 170 mbstring_binary_safe_encoding(); 171 169 172 if ( ! isset( $r['headers']['Accept-Encoding'] ) ) { 170 173 if ( $encoding = WP_Http_Encoding::accept_encoding( $url, $r ) ) 171 174 $r['headers']['Accept-Encoding'] = $encoding; … … 187 190 } 188 191 189 192 $response = $this->_dispatch_request( $url, $r ); 193 194 reset_mbstring_encoding(); 195 190 196 if ( is_wp_error( $response ) ) 191 197 return $response; 192 198 … … 1311 1317 * @return int 1312 1318 */ 1313 1319 private function stream_body( $handle, $data ) { 1314 if ( function_exists( 'ini_get' ) && ( ini_get( 'mbstring.func_overload' ) & 2 ) && function_exists( 'mb_internal_encoding' ) ) {1315 $mb_encoding = mb_internal_encoding();1316 mb_internal_encoding( 'ISO-8859-1' );1317 }1318 1319 1320 $data_length = strlen( $data ); 1320 1321 1321 1322 if ( $this->max_body_length && ( strlen( $this->body ) + $data_length ) > $this->max_body_length ) … … 1328 1329 $bytes_written = $data_length; 1329 1330 } 1330 1331 1331 if ( isset( $mb_encoding ) )1332 mb_internal_encoding( $mb_encoding );1333 1334 1332 // Upon event of this function returning less than strlen( $data ) curl will error with CURLE_WRITE_ERROR 1335 1333 return $bytes_written; 1336 1334 } -
src/wp-includes/functions.php
4092 4092 4093 4093 return $charset; 4094 4094 } 4095 4096 /** 4097 * Sets the mbstring internal encoding to a binary safe encoding whne func_overload is enabled. 4098 * 4099 * When mbstring.func_overload is in use for multi-byte encodings, the results from strlen() and 4100 * similar functions respect the utf8 characters, causing binary data to return incorrect lengths. 4101 * 4102 * This function overrides the mbstring encoding to a binary-safe encoding, and resets it to the 4103 * users expected encoding afterwards through the `reset_mbstring_encoding` function. 4104 * 4105 * It is safe to recursively call this function, however each `mbstring_binary_safe_encoding` call 4106 * must be followed up with an equal number of `reset_mbstring_encoding` calls. 4107 * 4108 * @see reset_mbstring_encoding() 4109 * 4110 * @since 3.7.0 4111 * 4112 * @param bool $reset Whether to reset the encoding back to a previously-set encoding. 4113 */ 4114 function mbstring_binary_safe_encoding( $reset = false ) { 4115 static $encodings = array(); 4116 static $overloaded = null; 4117 4118 if ( is_null( $overloaded ) ) 4119 $overloaded = function_exists( 'ini_get' ) && ( ini_get( 'mbstring.func_overload' ) & 2 ) && function_exists( 'mb_internal_encoding' ); 4120 4121 if ( false === $overloaded ) 4122 return; 4123 4124 if ( ! $reset ) { 4125 $encoding = mb_internal_encoding(); 4126 array_push( $encodings, $encoding ); 4127 mb_internal_encoding( 'ISO-8859-1' ); 4128 } 4129 4130 if ( $reset && $encodings ) { 4131 $encoding = array_pop( $encodings ); 4132 mb_internal_encoding( $encoding ); 4133 } 4134 } 4135 4136 /** 4137 * Resets the mbstring internal encoding to a users previously set encoding. 4138 * 4139 * @see mbstring_binary_safe_encoding() 4140 * 4141 * @since 3.7.0 4142 */ 4143 function reset_mbstring_encoding() { 4144 mbstring_binary_safe_encoding( true ); 4145 } 4146 No newline at end of file -
src/wp-admin/includes/file.php
642 642 function _unzip_file_pclzip($file, $to, $needed_dirs = array()) { 643 643 global $wp_filesystem; 644 644 645 // See #15789 - PclZip uses string functions on binary data, If it's overloaded with Multibyte safe functions the results are incorrect. 646 if ( ( ini_get('mbstring.func_overload') & 2 ) && function_exists('mb_internal_encoding') ) { 647 $previous_encoding = mb_internal_encoding(); 648 mb_internal_encoding('ISO-8859-1'); 649 } 645 mbstring_binary_safe_encoding(); 650 646 651 647 require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php'); 652 648 … … 654 650 655 651 $archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING); 656 652 657 if ( isset($previous_encoding) ) 658 mb_internal_encoding($previous_encoding); 653 reset_mbstring_encoding(); 659 654 660 655 // Is the archive valid? 661 656 if ( !is_array($archive_files) )