Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle negative ini sizes #703

Merged
merged 1 commit into from Oct 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 23 additions & 11 deletions htdocs/class/uploader.php
Expand Up @@ -152,16 +152,12 @@ public function __construct($uploadDir, $allowedMimeTypes, $maxFileSize = 0, $ma
}
$this->uploadDir = $uploadDir;

$maxUploadInBytes = $this->return_bytes(ini_get('upload_max_filesize'));
$maxPostInBytes = $this->return_bytes(ini_get('post_max_size'));
$memoryLimitInBytes = $this->return_bytes(ini_get('memory_limit'));
if ((int)$maxFileSize > 0) {
$maxFileSizeInBytes = $this->return_bytes($maxFileSize);
$newMaxFileSize = min($maxFileSizeInBytes, $maxUploadInBytes, $maxPostInBytes, $memoryLimitInBytes);
} else {
$newMaxFileSize = min($maxUploadInBytes, $maxPostInBytes, $memoryLimitInBytes);
}
$this->maxFileSize = $newMaxFileSize;
$limits = array();
$limits = $this->arrayPushIfPositive($limits, $maxFileSize);
$limits = $this->arrayPushIfPositive($limits, $this->return_bytes(ini_get('upload_max_filesize')));
$limits = $this->arrayPushIfPositive($limits, $this->return_bytes(ini_get('post_max_size')));
$limits = $this->arrayPushIfPositive($limits, $this->return_bytes(ini_get('memory_limit')));
$this->maxFileSize = min($limits);

if (isset($maxWidth)) {
$this->maxWidth = (int)$maxWidth;
Expand Down Expand Up @@ -214,7 +210,7 @@ public function countMedia($media_name) {
}
return count($_FILES[$media_name]['name']);
}

/**
* Fetch the uploaded file
*
Expand Down Expand Up @@ -666,4 +662,20 @@ public function &getErrors($ashtml = true)
return $ret;
}
}

/**
* Push value onto set.
* Used in max file size calculation to eliminate -1 (unlimited) ini values
*
* @param array $set array of values
* @param int $value value to push
*
* @return mixed
*/
protected function arrayPushIfPositive($set, $value) {
if ($value > 0) {
array_push($set, $value);
}
return $set;
}
}