Added handling as infinity if maxfilesize is set to 0

This commit is contained in:
Marek Bachmann 2022-11-30 02:44:48 +01:00
parent ca7af7a64b
commit 97a3587e58
2 changed files with 16 additions and 1 deletions

View file

@ -656,6 +656,10 @@ function photos_post(App $a)
$maximagesize = Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
if ($maximagesize == 0) {
$maximagesize = INF;
}
if ($maximagesize && ($filesize > $maximagesize)) {
DI::sysmsg()->addNotice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
@unlink($src);
@ -918,10 +922,12 @@ function photos_content(App $a)
// Get the relevant size limits for uploads. Abbreviated var names: MaxImageSize -> mis; upload_max_filesize -> umf
$mis_bytes = Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
$umf_bytes = Strings::getBytesFromShorthand(ini_get('upload_max_filesize'));
// Per Friendica definition a value of '0' mean unlimited:
// Per Friendica definition a value of '0' means unlimited:
If ($mis_bytes == 0) {
$mis_bytes = INF;
}
// When PHP is configured with upload_max_filesize less than maximagesize provide this lower limit.
$maximagesize_Mbytes = (is_numeric($mis_bytes) && ($mis_bytes < $umf_bytes) ? $mis_bytes : $umf_bytes) / (1048576);

View file

@ -576,6 +576,11 @@ class Photo
$filesize = strlen($image->asString());
$maximagesize = Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
if ($maximagesize == 0) {
$maximagesize = INF;
}
if (!empty($maximagesize) && ($filesize > $maximagesize)) {
Logger::info('Avatar exceeds image limit', ['uid' => $uid, 'cid' => $cid, 'maximagesize' => $maximagesize, 'size' => $filesize, 'type' => $image->getType()]);
if ($image->getType() == 'image/gif') {
@ -968,6 +973,10 @@ class Photo
$maximagesize = Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
if ($maximagesize == 0) {
$maximagesize = INF;
}
if (!empty($maximagesize) && ($filesize > $maximagesize)) {
// Scale down to multiples of 640 until the maximum size isn't exceeded anymore
foreach ([5120, 2560, 1280, 640] as $pixels) {