Page MenuHomePhabricator

Upload API does not handle very large files correctly
Open, Needs TriagePublic

Description

When files exceed the maximum file size allowed by the wiki or PHP (i.e. upload_max_filesize), the upload API will return an error badupload, with an error message explaining the error. However, if the total request size exceeds the value of post_max_size, the upload API does not return a JSON response. Instead, it returns the "MediaWiki API help" HTML page. This causes an error in the upload API JavaScript code: HTTP error: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data.

mediawiki_upload_api.png (1×1 px, 175 KB)

Event Timeline

That seems the php internal behaviour as the documentation says:

https://www.php.net/manual/en/ini.core.php#ini.post-max-size

If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty.

The api does not get any hint about the missing arguments. Put at least the format and the action in the url (not api.php alone, but api.php?action=format&action=upload) to avoid getting the help in html, which is the default for an empty request. With format and action the response would provide a error about missing parameter.