aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/files.php
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@karoshi.org.uk>2015-07-20 15:03:09 +0100
committerRobin McCorkell <rmccorkell@karoshi.org.uk>2015-07-20 15:03:09 +0100
commitaac84f732dd192a5f13fe4b31ad0a384d6aa890b (patch)
treed5059d3acf92d4613c8659da7ff52821528c8f54 /lib/private/files.php
parentd3bcafe6185c30d2e2bfecbd919568a8197818bc (diff)
downloadnextcloud-server-aac84f732dd192a5f13fe4b31ad0a384d6aa890b.tar.gz
nextcloud-server-aac84f732dd192a5f13fe4b31ad0a384d6aa890b.zip
Unit test OC_Files::setUploadLimit()
There was also a bug with checking the upper limit on the passed upload size. PHP does funny things with integer vs float comparisons, so our check didn't work. Now the check is much simpler, and ensures the value is sane.
Diffstat (limited to 'lib/private/files.php')
-rw-r--r--lib/private/files.php25
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/private/files.php b/lib/private/files.php
index b9fd1093319..6268bf8a129 100644
--- a/lib/private/files.php
+++ b/lib/private/files.php
@@ -269,37 +269,34 @@ class OC_Files {
* set the maximum upload size limit for apache hosts using .htaccess
*
* @param int $size file size in bytes
+ * @param array $files override '.htaccess' and '.user.ini' locations
* @return bool false on failure, size on success
*/
- static function setUploadLimit($size) {
+ public static function setUploadLimit($size, $files = []) {
//don't allow user to break his config
- if ($size > PHP_INT_MAX) {
- //max size is always 1 byte lower than computerFileSize returns
- if ($size > PHP_INT_MAX + 1)
- return false;
- $size -= 1;
- }
+ $size = intval($size);
if ($size < self::UPLOAD_MIN_LIMIT_BYTES) {
return false;
}
$size = OC_Helper::phpFileSize($size);
- //don't allow user to break his config -- broken or malicious size input
- if (intval($size) === 0) {
- return false;
- }
-
$phpValueKeys = array(
'upload_max_filesize',
'post_max_size'
);
+ // default locations if not overridden by $files
+ $files = array_merge([
+ '.htaccess' => OC::$SERVERROOT . '/.htaccess',
+ '.user.ini' => OC::$SERVERROOT . '/.user.ini'
+ ], $files);
+
$updateFiles = [
- OC::$SERVERROOT . '/.htaccess' => [
+ $files['.htaccess'] => [
'pattern' => '/php_value %1$s (\S)*/',
'setting' => 'php_value %1$s %2$s'
],
- OC::$SERVERROOT . '/.user.ini' => [
+ $files['.user.ini'] => [
'pattern' => '/%1$s=(\S)*/',
'setting' => '%1$s=%2$s'
]