wp_convert_hr_to_bytes() fails on large numeric values
|Reported by:||hakre||Owned by:|
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 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.