From 97a3587e5821d6d2208d38941b36118e7da17059 Mon Sep 17 00:00:00 2001 From: Marek Bachmann Date: Wed, 30 Nov 2022 02:44:48 +0100 Subject: [PATCH] Added handling as infinity if maxfilesize is set to 0 --- mod/photos.php | 8 +++++++- src/Model/Photo.php | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mod/photos.php b/mod/photos.php index d31f8daab5..9624982ca9 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -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); diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 967c58e2ab..1250ad570b 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -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) {