Skip to content

Commit

Permalink
Merge pull request #9 from MittagQI/hotfix/slow-bodychunk-decode-for-…
Browse files Browse the repository at this point in the history
…large-text

restore mbstring overloading for full backwards compatibility
  • Loading branch information
thomaslauria authored Jul 22, 2024
2 parents 077977a + 78f59e6 commit 09cef7b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion library/Zend/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,16 @@ public static function extractBody($response_str)
public static function decodeChunkedBody($body)
{
$decBody = '';

$offset = 0;

// If mbstring overloads substr and strlen functions, we have to
// override it's internal encoding
if (function_exists('mb_internal_encoding') &&
((int) ini_get('mbstring.func_overload')) & 2) {
$mbIntEnc = mb_internal_encoding();
mb_internal_encoding('ASCII');
}

while (true) {
if (! preg_match("/^([\da-fA-F]+)[^\r\n]*\r\n/sm", $body, $m, 0, $offset)) {
if (trim(substr($body, $offset))) {
Expand All @@ -610,6 +617,10 @@ public static function decodeChunkedBody($body)
$offset += $cut + $length + 2;
}

if (isset($mbIntEnc)) {
mb_internal_encoding($mbIntEnc);
}

return $decBody;
}

Expand Down

0 comments on commit 09cef7b

Please sign in to comment.