From 682e028a5afcc9d25e4f55d9bd14edf45f3d22ea Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Fri, 8 Jul 2016 12:54:28 +0000 Subject: [PATCH] Bootstrap: Clean up `wp_convert_hr_to_bytes()`. * Don't return a value higher than `PHP_INT_MAX`. * Add unit tests. Props jrf. See #32075. Built from https://develop.svn.wordpress.org/trunk@38013 git-svn-id: http://core.svn.wordpress.org/trunk@37954 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/load.php | 33 ++++++++++++++++++++------------- wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/wp-includes/load.php b/wp-includes/load.php index 6699495fc4..ebaaa353a0 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -956,7 +956,7 @@ function wp_installing( $is_installing = null ) { * Determines if SSL is used. * * @since 2.6.0 - * @since 4.6.0 Moved from functions.php to load.php + * @since 4.6.0 Moved from functions.php to load.php. * * @return bool True if SSL, otherwise false. */ @@ -979,19 +979,26 @@ function is_ssl() { * Converts a shorthand byte value to an integer byte value. * * @since 2.3.0 - * @since 4.6.0 Moved from media.php to load.php + * @since 4.6.0 Moved from media.php to load.php. * - * @param string $size A shorthand byte value. + * @link http://php.net/manual/en/function.ini-get.php + * @link http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes + * + * @param string $value A (PHP ini) byte value, either shorthand or ordinary. * @return int An integer byte value. */ -function wp_convert_hr_to_bytes( $size ) { - $size = strtolower( $size ); - $bytes = (int) $size; - if ( strpos( $size, 'k' ) !== false ) - $bytes = intval( $size ) * KB_IN_BYTES; - elseif ( strpos( $size, 'm' ) !== false ) - $bytes = intval($size) * MB_IN_BYTES; - elseif ( strpos( $size, 'g' ) !== false ) - $bytes = intval( $size ) * GB_IN_BYTES; - return $bytes; +function wp_convert_hr_to_bytes( $value ) { + $value = strtolower( trim( $value ) ); + $bytes = (int) $value; + + if ( false !== strpos( $value, 'g' ) ) { + $bytes *= GB_IN_BYTES; + } elseif ( false !== strpos( $value, 'm' ) ) { + $bytes *= MB_IN_BYTES; + } elseif ( false !== strpos( $value, 'k' ) ) { + $bytes *= KB_IN_BYTES; + } + + // Deal with large (float) values which run into the maximum integer size. + return min( $bytes, PHP_INT_MAX ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 1cb0a582e6..10ee0389fe 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-beta2-38012'; +$wp_version = '4.6-beta2-38013'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.