[wp-trac] [WordPress Trac] #17725: wp_convert_hr_to_bytes() fails on large numeric values

WordPress Trac wp-trac at lists.automattic.com
Wed Jun 8 12:24:41 UTC 2011


#17725: wp_convert_hr_to_bytes() fails on large numeric values
--------------------------+-----------------------------
 Reporter:  hakre         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  3.2
 Severity:  normal        |   Keywords:  has-patch
--------------------------+-----------------------------
 The {{{wp_convert_hr_to_bytes()}}} function exists to convert values in
 form of a memory setting into it's value in bytes.

 By doing so, the function modifies the input value in every case. This
 modification has an issue with integer limits.

 Whenever a value of $size is passed to the function that is in it's
 numerical part larger than
 [http://php.net/manual/en/reserved.constants.php PHP_INT_MAX], the input
 value will be capped to {{{PHP_INT_MAX}}}.

 This is an integer overflow.

 This applies as well when size has a shorthand ending specifier and it's
 numerical part is greater than PHP_INT_MAX.

 To illustrate the problem on a 32 bit system:

 {{{
         $setting = '2147483648';
         echo "'$setting' are ", wp_convert_hr_to_bytes($setting), "
 bytes.\n";
         // '2147483648' are 2147483647 bytes.
 }}}

 It shows that the last byte is missing. Every other byte on top will be
 capped as well. The number of bytes given are a value equally to '2G'.

 Solution: Input values should not be capped to int but to float which has
 allows higher values.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17725>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list