Skip to content

Commit

Permalink
Chunked decoding fix from jacobsantos. fixes #8618 for 2.7
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.automattic.com/wordpress/branches/2.7@10284 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
ryan committed Dec 31, 2008
1 parent 04ddd8c commit 3b4b6e3
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions wp-includes/http.php
Expand Up @@ -391,7 +391,7 @@ function processHeaders($headers) {
* @static
*
* @param string $body Body content
* @return bool|string|WP_Error False if not chunked encoded. WP_Error on failure. Chunked decoded body on success.
* @return string Chunked decoded body on success or raw body on failure.
*/
function chunkTransferDecode($body) {
$body = str_replace(array("\r\n", "\r"), "\n", $body);
Expand All @@ -402,15 +402,12 @@ function chunkTransferDecode($body) {
$parsedBody = '';
//$parsedHeaders = array(); Unsupported

$done = false;

do {
while ( true ) {
$hasChunk = (bool) preg_match( '/^([0-9a-f]+)(\s|\n)+/mi', $body, $match );

if ( $hasChunk ) {
if ( empty($match[1]) ) {
return new WP_Error('http_chunked_decode', __('Does not appear to be chunked encoded or body is malformed.') );
}
if ( empty($match[1]) )
return $body;

$length = hexdec( $match[1] );
$chunkLength = strlen( $match[0] );
Expand All @@ -420,15 +417,12 @@ function chunkTransferDecode($body) {

$body = ltrim(str_replace(array($match[0], $strBody), '', $body), "\n");

if( "0" == trim($body) ) {
$done = true;
if( "0" == trim($body) )
return $parsedBody; // Ignore footer headers.
break;
}
} else {
return new WP_Error('http_chunked_decode', __('Does not appear to be chunked encoded or body is malformed.') );
return $body;
}
} while ( false === $done );
}
}
}

Expand Down

0 comments on commit 3b4b6e3

Please sign in to comment.