Make WordPress Core

Ticket #25259: 25259.diff

File 25259.diff, 4.4 KB (added by dd32, 11 years ago)
  • src/wp-includes/class-http.php

     
    166166                // Construct Cookie: header if any cookies are set
    167167                WP_Http::buildCookieHeader( $r );
    168168
     169                // Avoid issues where mbstring.func_overload is enabled
     170                mbstring_binary_safe_encoding();
     171
    169172                if ( ! isset( $r['headers']['Accept-Encoding'] ) ) {
    170173                        if ( $encoding = WP_Http_Encoding::accept_encoding( $url, $r ) )
    171174                                $r['headers']['Accept-Encoding'] = $encoding;
     
    187190                }
    188191
    189192                $response = $this->_dispatch_request( $url, $r );
     193
     194                reset_mbstring_encoding();
     195
    190196                if ( is_wp_error( $response ) )
    191197                        return $response;
    192198
     
    13111317         * @return int
    13121318         */
    13131319        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 
    13191320                $data_length = strlen( $data );
    13201321
    13211322                if ( $this->max_body_length && ( strlen( $this->body ) + $data_length ) > $this->max_body_length )
     
    13281329                        $bytes_written = $data_length;
    13291330                }
    13301331
    1331                 if ( isset( $mb_encoding ) )
    1332                         mb_internal_encoding( $mb_encoding );
    1333 
    13341332                // Upon event of this function returning less than strlen( $data ) curl will error with CURLE_WRITE_ERROR
    13351333                return $bytes_written;
    13361334        }
  • src/wp-includes/functions.php

     
    40924092
    40934093        return $charset;
    40944094}
     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 */
     4114function 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 */
     4143function reset_mbstring_encoding() {
     4144        mbstring_binary_safe_encoding( true );
     4145}
     4146 No newline at end of file
  • src/wp-admin/includes/file.php

     
    642642function _unzip_file_pclzip($file, $to, $needed_dirs = array()) {
    643643        global $wp_filesystem;
    644644
    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();
    650646
    651647        require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
    652648
     
    654650
    655651        $archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING);
    656652
    657         if ( isset($previous_encoding) )
    658                 mb_internal_encoding($previous_encoding);
     653        reset_mbstring_encoding();
    659654
    660655        // Is the archive valid?
    661656        if ( !is_array($archive_files) )