WordPress.org

Make WordPress Core

Ticket #22952: 22952.2.diff

File 22952.2.diff, 2.2 KB (added by dd32, 5 years ago)
  • wp-includes/class-http.php

     
    16531653                if ( empty($compressed) )
    16541654                        return $compressed;
    16551655
    1656                 if ( false !== ( $decompressed = @gzinflate( $compressed ) ) )
    1657                         return $decompressed;
    1658 
    16591656                if ( false !== ( $decompressed = WP_Http_Encoding::compatible_gzinflate( $compressed ) ) )
    16601657                        return $decompressed;
    16611658
     
    16941691         */
    16951692        public static function compatible_gzinflate($gzData) {
    16961693
    1697                 // Compressed data might contain a full header, if so strip it for gzinflate()
     1694                // Compressed data might contain a full zlib header, if so strip it for gzinflate()
    16981695                if ( substr($gzData, 0, 3) == "\x1f\x8b\x08" ) {
    16991696                        $i = 10;
    17001697                        $flg = ord( substr($gzData, 3, 1) );
     
    17151712                                return $decompressed;
    17161713                }
    17171714
    1718                 // Compressed data from java.util.zip.Deflater amongst others.
    1719                 $decompressed = @gzinflate( substr($gzData, 2) );
    1720                 if ( false !== $decompressed )
     1715                // If the data is Huffman Encoded, we must first strip the leading 2 byte Huffman marker for gzinflate()
     1716                // The Response is Huffman coded by many compressors such as java.util.zip.Deflater,
     1717                // Ruby’s Zlib::Deflate, and .NET's System.IO.Compression.DeflateStream.
     1718                // See http://decompres.blogspot.com/ for a quick explanation of this data type
     1719                $huffman_encoded = false;
     1720                list( , $first_nibble ) = unpack( 'h', $gzData ); // low nibble of first byte should be 0x08
     1721                list( , $first_two_bytes ) = unpack( 'n', $gzData ); // First 2 bytes should be divisible by 0x1F
     1722                if ( 0x08 == $first_nibble && 0 == ( $first_two_bytes % 0x1F ) )
     1723                        $huffman_encoded = true;
     1724
     1725                if ( $huffman_encoded ) {
     1726                        if ( false !== ( $decompressed = @gzinflate( substr( $gzData, 2 ) ) ) )
     1727                                return $decompressed;
     1728                }
     1729
     1730                // Finally fall back to straight gzinflate
     1731                if ( false !== ( $decompressed = @gzinflate( $gzData ) ) )
    17211732                        return $decompressed;
    17221733
     1734                // Fallback for all above failing, not expected, but included for debugging and preventing regressions
     1735                if ( false !== ( $decompressed = @gzinflate( substr( $gzData, 2 ) ) ) )
     1736                        return $decompressed;
     1737
    17231738                return false;
    17241739        }
    17251740