joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

Incorrect file size validation in media manager - Joomla 4.4

Open paulkosciecha opened this issue 10 months ago • 5 comments

Steps to reproduce the issue

  • Set filesize limit in 4mb in Mediamanager settings
  • Upload file under 1mb - uploads fine
  • Upload file of 3.5mb - get error message that file is too large
  • Upload file of 8mb+ - get message saying file uploaded, blue line progresses, but no file appears

Expected result

Error reporting should be consistent with the scenario. It should not say the file is too large when it isn't bigger than the limits set in mediamanager - if these are lower than php. It should throw the error when the file is too big and not say it is uploaded.

Actual result

File is too big Error throws in scenerio where file is below the threshold. File uploaded message where the file is too big.

System information (as much as possible)

  • Joomla 4.4.0
  • Mamp server run locally as dev
  • php.ini - post_max_size = 8M, upload_max_filesize = 32M
  • Safari browser

Additional comments

paulkosciecha avatar Apr 27 '24 13:04 paulkosciecha

The 3.5 issue could be the result of rounding a float to an integer in combination with wrong logic so >= is used instead of > (which would be wrong of course, am just thinking about what could cause that).

richard67 avatar Apr 28 '24 08:04 richard67

Confirmed using Joomla 5.1

  • media manager set to 4mb

  • php Upload Max Filesize 100M

  • php Post Max Size 100M

Test 1 (filesmall.jpg 467kb) ✔️

image

Test 2 (filemed.jpg 3,792kb) ❌

image

Test 3 (filelarge.jpg 4,500kb) ✔️

image

brianteeman avatar Apr 28 '24 09:04 brianteeman

I'm debugging this issue and found that the Upload function of the Media Manager is using the File: readAsDataURL() method where the file's data is represented as a base64 encoded string.

That means the size of the Base64 version of the file is typically roughly a third larger than its source, refer to Encoded size increase For example if the file size is 3.5mb (3670016 bytes), the size of its Base64 version will be ~4881121 bytes. In our case the filesize limit is set to 4mb (4194304 bytes), it is clear enough that the size of the Base64 version is larger than the filesize limit, so the upload is failed and says the file is to large to upload!

I tried multiplying filesize limit by 1.33 before checking the file size and it works: $paramsUploadMaxsize = $params->get('upload_maxsize', 0) * 1024 * 1024 * 1.33;

but I'm not sure whether this is the best approach to handle it, please let me know your thoughts.

mabdelaziz77 avatar May 10 '24 21:05 mabdelaziz77

Hi, I have this issue too. PHP and Media Manager's limits set to 100MB, which workt for files up to ~50 MB. After that a blue progress line, even a success message, but no file uploaded. On the other hand, if I upload a file with JCE I can go up to 95 MB as expected. So it must be a Media Manager issue. On Joomla 4 and 5.

System1: PHP 8.1.29, Joomla 4.4.5 System2: PHP 8.2.20, Joomla 5.1.1

EricdeWaal avatar Jun 20 '24 16:06 EricdeWaal

Update: when I set the memory_limit to 384 MB (the highest value that my hoster allows) the max file size that can be uploaded goes up a bit, but never comes even near 100 MB,

EricdeWaal avatar Jun 21 '24 11:06 EricdeWaal

I have converted the suggestion into a pull request for testing see #43899

brianteeman avatar Aug 10 '24 08:08 brianteeman

Closing as having a pull request. Please test #43899 . Thanks in advance.

richard67 avatar Aug 10 '24 10:08 richard67

New pull request is #43906 . Please test. Thanks in advance.

richard67 avatar Aug 11 '24 15:08 richard67