diff --git a/.appveyor.yml b/.appveyor.yml index a89445a65b..a2f36f9d97 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -26,6 +26,8 @@ install: - echo memory_limit=-1 >> php.ini-min - echo serialize_precision=14 >> php.ini-min - echo max_execution_time=1200 >> php.ini-min + - echo post_max_size=4G >> php.ini-min + - echo upload_max_filesize=4G >> php.ini-min - echo date.timezone="America/Los_Angeles" >> php.ini-min - echo extension_dir=ext >> php.ini-min - echo extension=php_xsl.dll >> php.ini-min diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php index 81d0eb06b9..4ccf94c920 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php @@ -178,8 +178,10 @@ class FileType extends AbstractType * Returns the maximum size of an uploaded file as configured in php.ini. * * This method should be kept in sync with Symfony\Component\HttpFoundation\File\UploadedFile::getMaxFilesize(). + * + * @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX) */ - private static function getMaxFilesize(): int + private static function getMaxFilesize() { $iniMax = strtolower(ini_get('upload_max_filesize')); @@ -214,8 +216,10 @@ class FileType extends AbstractType * (i.e. try "MB", then "kB", then "bytes"). * * This method should be kept in sync with Symfony\Component\Validator\Constraints\FileValidator::factorizeSizes(). + * + * @param int|float $limit */ - private function factorizeSizes(int $size, int $limit) + private function factorizeSizes(int $size, $limit) { $coef = self::MIB_BYTES; $coefFactor = self::KIB_BYTES; diff --git a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php index 682bdff741..575d5087df 100644 --- a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php +++ b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php @@ -239,7 +239,7 @@ class UploadedFile extends File /** * Returns the maximum size of an uploaded file as configured in php.ini. * - * @return int The maximum size of an uploaded file in bytes + * @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX) */ public static function getMaxFilesize() { @@ -251,8 +251,10 @@ class UploadedFile extends File /** * Returns the given size from an ini value in bytes. + * + * @return int|float Returns float if size > PHP_INT_MAX */ - private static function parseFilesize($size): int + private static function parseFilesize($size) { if ('' === $size) { return 0; diff --git a/src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php b/src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php index cf0019212b..590483214d 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\File\Exception\CannotWriteFileException; use Symfony\Component\HttpFoundation\File\Exception\ExtensionFileException; use Symfony\Component\HttpFoundation\File\Exception\FileException; +use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\File\Exception\FormSizeFileException; use Symfony\Component\HttpFoundation\File\Exception\IniSizeFileException; use Symfony\Component\HttpFoundation\File\Exception\NoFileException; @@ -33,7 +34,7 @@ class UploadedFileTest extends TestCase public function testConstructWhenFileNotExists() { - $this->expectException(\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException::class); + $this->expectException(FileNotFoundException::class); new UploadedFile( __DIR__.'/Fixtures/not_here', @@ -358,13 +359,16 @@ class UploadedFileTest extends TestCase { $size = UploadedFile::getMaxFilesize(); - $this->assertIsInt($size); + if ($size > \PHP_INT_MAX) { + $this->assertIsFloat($size); + } else { + $this->assertIsInt($size); + } + $this->assertGreaterThan(0, $size); if (0 === (int) ini_get('post_max_size') && 0 === (int) ini_get('upload_max_filesize')) { $this->assertSame(\PHP_INT_MAX, $size); - } else { - $this->assertLessThan(\PHP_INT_MAX, $size); } } } diff --git a/src/Symfony/Component/Validator/Constraints/FileValidator.php b/src/Symfony/Component/Validator/Constraints/FileValidator.php index 3142f4cea6..9cc68346a5 100644 --- a/src/Symfony/Component/Validator/Constraints/FileValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FileValidator.php @@ -214,8 +214,10 @@ class FileValidator extends ConstraintValidator /** * Convert the limit to the smallest possible number * (i.e. try "MB", then "kB", then "bytes"). + * + * @param int|float $limit */ - private function factorizeSizes(int $size, int $limit, bool $binaryFormat): array + private function factorizeSizes(int $size, $limit, bool $binaryFormat): array { if ($binaryFormat) { $coef = self::MIB_BYTES; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php index 405fd3ab8d..d14374fe21 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php @@ -459,14 +459,12 @@ abstract class FileValidatorTest extends ConstraintValidatorTestCase [, $limit, $suffix] = $method->invokeArgs(new FileValidator(), [0, UploadedFile::getMaxFilesize(), false]); // it correctly parses the maxSize option and not only uses simple string comparison - // 1000M should be bigger than the ini value + // 1000G should be bigger than the ini value $tests[] = [(string) \UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', [ '{{ limit }}' => $limit, '{{ suffix }}' => $suffix, - ], '1000M']; + ], '1000G']; - // it correctly parses the maxSize option and not only uses simple string comparison - // 1000M should be bigger than the ini value $tests[] = [(string) \UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', [ '{{ limit }}' => '0.1', '{{ suffix }}' => 'MB',