Guard against mbstring func_overload, fixes #5218
parent
830644f374
commit
1bf711fe1f
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue