1
0
Fork 0

Guard against mbstring func_overload, fixes #5218

pull/5221/head
Jordi Boggiano 2016-04-19 15:43:59 +01:00
parent 830644f374
commit 1bf711fe1f
3 changed files with 20 additions and 2 deletions

View File

@ -76,7 +76,7 @@ class GzipDownloader extends ArchiveDownloader
$archiveFile = gzopen($file, 'rb'); $archiveFile = gzopen($file, 'rb');
$targetFile = fopen($targetFilepath, 'wb'); $targetFile = fopen($targetFilepath, 'wb');
while ($string = gzread($archiveFile, 4096)) { while ($string = gzread($archiveFile, 4096)) {
fwrite($targetFile, $string, strlen($string)); fwrite($targetFile, $string, Platform::strlen($string));
} }
gzclose($archiveFile); gzclose($archiveFile);
fclose($targetFile); fclose($targetFile);

View File

@ -26,4 +26,22 @@ class Platform
{ {
return defined('PHP_WINDOWS_VERSION_BUILD'); return defined('PHP_WINDOWS_VERSION_BUILD');
} }
/**
* @param string $str
* @return int return a guaranteed binary length of the string, regardless of silly mbstring configs
*/
public static function strlen($str)
{
static $useMbString = null;
if (null === $useMbString) {
$useMbString = function_exists('mb_strlen') && ini_get('mbstring.func_overload');
}
if ($useMbString) {
return mb_strlen($str, '8bit');
}
return strlen($str);
}
} }

View File

@ -277,7 +277,7 @@ class RemoteFilesystem
try { try {
$result = file_get_contents($fileUrl, false, $ctx); $result = file_get_contents($fileUrl, false, $ctx);
if ($this->bytesMax && strlen($result) < $this->bytesMax) { if ($this->bytesMax && Platform::strlen($result) < $this->bytesMax) {
// alas, this is not possible via the stream callback because STREAM_NOTIFY_COMPLETED is documented, but not implemented anywhere in PHP // alas, this is not possible via the stream callback because STREAM_NOTIFY_COMPLETED is documented, but not implemented anywhere in PHP
throw new TransportException('Content-Length mismatch'); throw new TransportException('Content-Length mismatch');
} }