Skip to content

Commit

Permalink
[4.0] php memory limit
Browse files Browse the repository at this point in the history
It is possible to set the memory limit in php to -1 which means unlimited memory.

Unfortunately this was not accounted for in the maths to check if a file could be uploaded.

To test you will need to change the value in your php.ini to `memory_limit = -1` and restart the web server.

Then try to upload any file in the media manager and you will see an error message that the file is too large.

Apply this PR and the upload will be successful.

PR for #35853
  • Loading branch information
brianteeman committed Oct 19, 2021
1 parent 32f1809 commit 43ccd32
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ public function getItems()
'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_UPLOADBIGGERTHANPOSTDESC'));
}

if ($post_max_size < $minMemory)
if ($post_max_size < $minMemory && $memory_limit != -1)
{
$messages[] = array('message' => Text::_('COM_INSTALLER_MSG_WARNINGS_SMALLPOSTSIZE'),
'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_SMALLPOSTSIZEDESC'));
}

if ($upload_max_filesize < $minMemory)
if ($upload_max_filesize < $minMemory && $memory_limit != -1)
{
$messages[] = array('message' => Text::_('COM_INSTALLER_MSG_WARNINGS_SMALLUPLOADSIZE'),
'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_SMALLUPLOADSIZEDESC'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ private function checkContent()
if (($params->get('upload_maxsize', 0) > 0 && $serverlength > ($params->get('upload_maxsize', 0) * 1024 * 1024))
|| $serverlength > $helper->toBytes(ini_get('upload_max_filesize'))
|| $serverlength > $helper->toBytes(ini_get('post_max_size'))
|| $serverlength > $helper->toBytes(ini_get('memory_limit')))
|| $serverlength > $helper->toBytes(ini_get('memory_limit')) && $helper->toBytes(ini_get('memory_limit')) != -1)
{
throw new \Exception(Text::_('COM_MEDIA_ERROR_WARNFILETOOLARGE'), 403);
}
Expand Down

0 comments on commit 43ccd32

Please sign in to comment.