post-max-size exceeding error is not tracked

Bug #634193 reported by Ruslan Kabalin on 2010-09-09
24
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Mahara
Medium
Robert Lyon

Bug Description

If post-max-size PHP setting (http://php.net/manual/en/ini.core.php#ini.post-max-size) value is exceeded (by large file upload for example) no error is triggered, as result wherever upload is handled by ajax, no callback functions are called.

This is partly related to bugs:
   https://bugs.launchpad.net/mahara/+bug/633760
   https://bugs.launchpad.net/mahara/+bug/547505

Given that this error is triggered by PHP prior to processing the code, it can't be catch through exception. As forums suggests, it may worth using error_get_last() and grep result for "PHP Warning: POST Content-Length of" string.

tags: added: exception files
Ruslan Kabalin (rkabalin) wrote :

Possible workaround is to set post-max-size much higher than upload_max_filesize in php ini/.htaccess file, so that post-max-size will never be hit.

Setting post-max-size and upload_max_filesize to equal value means that upload_max_filesize will never be triggered, any file equal to upload_max_filesize will trigger post-max-size (because post-max-size consider the whole POST header size which has some data apart of the file content, see bug #634829).

Setting post-max-size a little bit higher than upload_max_filesize will not help either, it will only produce traceable file upload error if the file size is between upload_max_filesize and post-max-size, so the probability of having file in this gap is relatively small.

Post-max-size has the highest priority over file-related errors. Say, if file is higher than post-max-size, corresponding error will be triggered first despite having MAX_FILE_SIZE hidden value and/or upload_max_filesize set to lower value.

There was a related discussion here: http://mahara.org/interaction/forum/topic.php?id=831

Changed in mahara:
status: New → Confirmed
importance: Undecided → Low

From https://bugs.launchpad.net/mahara/+bug/781426:

"Let's add some warnings / error messages in 1.4 to preempt support requests on the forums."

The message should include something about setting post-max-size much higher than upload_max_filesize.

Changed in mahara:
milestone: none → 1.4.0
importance: Low → Medium
Changed in mahara:
assignee: nobody → Richard Mansfield (richard-mansfield)
Hugh Davenport (hugh-davenport) wrote :

could this be done with ini_set instead of htaccess file.
Either setting post_max_size to 0 or some large value.

Cheers,

Hugh

Changed in mahara:
status: Confirmed → In Progress
Ruslan Kabalin (rkabalin) wrote :

Richard, though your current solution is useful, it does not fix the bug. It is possible though to track that error using error_get_last(). I think we should leave this bug open yet until it is entirely fixed.

Agreed, but I'll take it out of 1.4.

Changed in mahara:
milestone: 1.4.0 → none
status: In Progress → Confirmed
assignee: Richard Mansfield (richard-mansfield) → nobody

We could use JavaScript to detect the post_max_size, but that would not be reliable. Instead we could adapt the current notification to recommend a higher value.

Changed in mahara:
milestone: none → 1.7.0
Aaron Wells (u-aaronw) on 2013-04-19
Changed in mahara:
milestone: 1.7.0 → 1.8.0
Robert Lyon (robertl-9) wrote :

Not sure if this may be of help:

In something I was working on there was a case where post_max_size can caused problem when exceeded as the $_POST becomes empty. To check for that I'd used the code:

if (empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
    $postmxsize = ini_get('post_max_size');
    $error_str = "Your file is too big. The maximum allowed size here is $postmaxsize.";
    echo json_encode($error_str);
}

I'm wondering if this is what is needed in the file that is called by ajax for this bug?

Changed in mahara:
milestone: 1.8.0rc1 → none
Son Nguyen (ngson2000) wrote :

Let me clear the problem

1. Catching the exception when uploaded file size is bigger than post_max_size
2. Displaying the error message

Son Nguyen (ngson2000) wrote :

Many places in Mahara use uploading files without tracking this errors

Here is the result of
 $ grep -r "'type'.*'file'" htdocs/
 htdocs/skin/import.php
 htdocs/import/index.php
 htdocs/admin/site/font/add.php
 htdocs/admin/site/font/installgwf.php
 htdocs/admin/site/font/install.php
 htdocs/admin/users/add.php
 htdocs/admin/users/institutions.php
 htdocs/admin/users/uploadcsv.php
 htdocs/admin/groups/uploadmemberscsv.php
 htdocs/admin/groups/uploadcsv.php
 htdocs/artefact/file/js/filebrowser.js
 htdocs/artefact/file/profileicons.php
 htdocs/artefact/file/import/leap/lib.php

Aaron Wells (u-aaronw) wrote :

We should add a check for this to the library methods that all of our file uploads go through. I believe most of the file upload code passes through some of the functions in mahara/lib/uploadmanager.php, and lib/form/elements/filebrowser.php . All the file uploads in Mahara should pass through some common library methods, because they also need to run the upload through ClamAV if it's turned on.

Robert Lyon (robertl-9) on 2017-10-16
Changed in mahara:
assignee: nobody → Robert Lyon (robertl-9)
Changed in mahara:
milestone: none → 18.04.0
Robert Lyon (robertl-9) on 2018-03-07
Changed in mahara:
milestone: 18.04.0 → 18.10.0
Robert Lyon (robertl-9) on 2018-07-12
Changed in mahara:
status: Confirmed → In Progress
Changed in mahara:
milestone: 18.10.0 → 19.04.0

Reviewed: https://reviews.mahara.org/9006
Committed: https://git.mahara.org/mahara/mahara/commit/640b642ff9e9e09290469dea4c9c5983f1f7605b
Submitter: Cecilia Vela Gurovic (<email address hidden>)
Branch: master

commit 640b642ff9e9e09290469dea4c9c5983f1f7605b
Author: Robert Lyon <email address hidden>
Date: Thu Jul 12 17:33:24 2018 +1200

Bug 634193: Checking for too big file before form submit

This should be ok as if the file is too big for quota then it will be
complained about. If it is too big for post_max_size then will error out

behatnotneeded

Change-Id: I0b4fc8cd6bfad9c302299e1ea14a8180d427b3c6
Signed-off-by: Robert Lyon <email address hidden>

Changed in mahara:
status: In Progress → Fix Committed
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers