From 4cdfb3f4eddb1c3ccaa304b1c8d3fade7e18f75e Mon Sep 17 00:00:00 2001 From: EA117 Date: Mon, 26 Aug 2019 21:07:01 -0500 Subject: [ticket/16141] plupload chunk_size incorrect when 'unlimited' is involved. Change get_chunk_size() calculation to correctly calculate limits without letting a zero "unlimited" value always win. Also ensure get_chunk_size() can only return zero if all of the limits were in fact set to unlimited. PHPBB3-16141 --- phpBB/phpbb/plupload/plupload.php | 52 +++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb/plupload/plupload.php') diff --git a/phpBB/phpbb/plupload/plupload.php b/phpBB/phpbb/plupload/plupload.php index eb698fb35d..ac4811e4ef 100644 --- a/phpBB/phpbb/plupload/plupload.php +++ b/phpBB/phpbb/plupload/plupload.php @@ -283,15 +283,51 @@ class plupload */ public function get_chunk_size() { - $max = min( - $this->php_ini->getBytes('upload_max_filesize'), - $this->php_ini->getBytes('post_max_size'), - max(1, $this->php_ini->getBytes('memory_limit')), - $this->config['max_filesize'] - ); + $max = 0; + + $limit = $this->php_ini->getBytes('memory_limit'); + + // unlimited is -1 for memory_limit. 0 would be an invalid configuration. + + if ($limit > 0) + { + $max = $limit; + } + + // For all remaining limits, 0 means "unlimited". + + // For each limit, if there is a non-unlimited value to + // apply, apply the limit if it's less than whatever non- + // unlimited max value is currently set. Also, apply the + // limit if the current max value is otherwise unlimited. + + $limit = $this->php_ini->getBytes('upload_max_filesize'); + + if ($limit > 0) + { + $max = min($limit, max($max, $limit)); + } + + $limit = $this->php_ini->getBytes('post_max_size'); + + if ($limit > 0) + { + $max = min($limit, max($max, $limit)); + } + + $limit = $this->config['max_filesize']; + + if ($limit > 0) + { + $max = min($limit, max($max, $limit)); + } + + // Only if every limit was 0/unlimited will we still + // have a zero value in $max at this point. + + // Use half of the maximum possible to leave plenty of + // room for other POST data and be well under limits. - // Use half of the maximum possible to leave plenty of room for other - // POST data. return floor($max / 2); } -- cgit v1.2.1