From 3536e18ab07e08311d44a5d9c2c0a1defde91ec5 Mon Sep 17 00:00:00 2001 From: David Hicks Date: Sat, 18 Sep 2010 14:10:44 +1000 Subject: [PATCH] Fix #7328: ini_get_number uses wrong postfix multipliers The ini_get_number function currently uses the wrong postfix multipliers when determining the integer value of configuration options from php.ini. The PHP manual clearly states that k = kibibyte instead of k = kilobyte as per http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes Thus we need to change the postfix multipliers to reflect what the PHP manual defines for php.ini. Thanks to Morgan Parry for providing a patch to this issue just over 4 years ago. And thanks to Roland Becker for bumping up old issues like this one that have been forgotten in the past. --- core/utility_api.php | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/core/utility_api.php b/core/utility_api.php index 013f093bca..57e308080a 100644 --- a/core/utility_api.php +++ b/core/utility_api.php @@ -103,20 +103,34 @@ function ini_get_bool( $p_name ) { } /** - * Get the named php ini variable but return it as a number after converting "K" and "M" - * @param string $p_name - * @return int + * Get the named php.ini variable but return it as a number after converting + * the giga (g/G), mega (m/M) and kilo (k/K) postfixes. These postfixes do not + * adhere to IEEE 1541 in that k=1024, not k=1000. For more information see + * http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes + * @param string $p_name Name of the configuration option to read. + * @return int Integer value of the configuration option. * @access public */ function ini_get_number( $p_name ) { - $t_result = ini_get( $p_name ); - $t_val = explode( 'm', strtolower( $t_result ) ); - if( $t_val[0] != $t_result ) { - return $t_val[0] * 1000000; - } - $t_val = explode( 'k', strtolower( $t_result ) ); - if( $t_val[0] != $t_result ) { - return $t_val[0] * 1000; + $t_value = ini_get( $p_name ); + + $t_result = 0; + switch( substr( $t_value, -1 ) ) { + case 'G': + case 'g': + $t_result = (int)$t_value * 1073741824; + break; + case 'M': + case 'm': + $t_result = (int)$t_value * 1048576; + break; + case 'K': + case 'k': + $t_result = (int)$t_value * 1024; + break; + default: + $t_result = (int)$t_value; + break; } return $t_result; }