Skip to content

Commit

Permalink
bug #33157 Fix getMaxFilesize() returning zero (ausi)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

Fix getMaxFilesize() returning zero

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #32790
| License       | MIT

With #32790 a BC break got introduced. Previously an empty `upload_max_filesize` returned `PHP_INT_MAX` but after the changes from #32790 it returns `0`.

Setting `upload_max_filesize` or `post_max_size` to `0` or `''` disables the limit so for both cases `PHP_INT_MAX` should be returned.

Commits
-------

f4c2ea5 Fix getMaxFilesize() returning zero
  • Loading branch information
fabpot committed Aug 14, 2019
2 parents 7ae7a66 + f4c2ea5 commit b382e62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/File/UploadedFile.php
Expand Up @@ -217,7 +217,7 @@ public static function getMaxFilesize()
$sizePostMax = self::parseFilesize(ini_get('post_max_size'));
$sizeUploadMax = self::parseFilesize(ini_get('upload_max_filesize'));

return min([$sizePostMax, $sizeUploadMax]);
return min($sizePostMax ?: PHP_INT_MAX, $sizeUploadMax ?: PHP_INT_MAX);
}

/**
Expand Down
Expand Up @@ -281,4 +281,18 @@ public function testIsInvalidIfNotHttpUpload()

$this->assertFalse($file->isValid());
}

public function testGetMaxFilesize()
{
$size = UploadedFile::getMaxFilesize();

$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);
}
}
}

0 comments on commit b382e62

Please sign in to comment.