Skip to content

Commit

Permalink
Fix #7328: ini_get_number uses wrong postfix multipliers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidhicks committed Sep 18, 2010
1 parent aa9540d commit 3536e18
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions core/utility_api.php
Expand Up @@ -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;
}
Expand Down

0 comments on commit 3536e18

Please sign in to comment.