Ticket #22952: 22952.diff
File 22952.diff, 2.2 KB (added by , 12 years ago) |
---|
-
wp-includes/class-http.php
1653 1653 if ( empty($compressed) ) 1654 1654 return $compressed; 1655 1655 1656 if ( false !== ( $decompressed = @gzinflate( $compressed ) ) )1657 return $decompressed;1658 1659 1656 if ( false !== ( $decompressed = WP_Http_Encoding::compatible_gzinflate( $compressed ) ) ) 1660 1657 return $decompressed; 1661 1658 … … 1694 1691 */ 1695 1692 public static function compatible_gzinflate($gzData) { 1696 1693 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() 1698 1695 if ( substr($gzData, 0, 3) == "\x1f\x8b\x08" ) { 1699 1696 $i = 10; 1700 1697 $flg = ord( substr($gzData, 3, 1) ); … … 1715 1712 return $decompressed; 1716 1713 } 1717 1714 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[0] ); // low nibble of first byte should be 0x08 1721 list( $first_two_bytes ) = unpack( 'n', substr( $gzData, 0, 2 ) ); // 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 ) ) ) 1721 1732 return $decompressed; 1722 1733 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 1723 1738 return false; 1724 1739 } 1725 1740