From fad1821dd7028a70558f7be40bb037b31c19084e Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 5 Aug 2019 13:54:43 +0000 Subject: [PATCH] General: Correctly detect large floats in `is_serialized()`. Props killerbishop, donmhico, hoythan. Fixes #46570. git-svn-id: https://develop.svn.wordpress.org/trunk@45754 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 2 +- tests/phpunit/tests/functions.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index df4f561840..019f8b6bf6 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -528,7 +528,7 @@ function is_serialized( $data, $strict = true ) { case 'i': case 'd': $end = $strict ? '$' : ''; - return (bool) preg_match( "/^{$token}:[0-9.E-]+;$end/", $data ); + return (bool) preg_match( "/^{$token}:[0-9.E+-]+;$end/", $data ); } return false; } diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 53f6e2cd5c..12ad13a78c 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -229,6 +229,20 @@ class Tests_Functions extends WP_UnitTestCase { } } + /** + * @ticket 46570 + */ + function test_is_serialized_should_return_true_for_large_floats() { + $cases = array( + serialize( 1.7976931348623157E+308 ), + serialize( array( 1.7976931348623157E+308, 1.23e50 ) ) + ); + + foreach ( $cases as $case ) { + $this->assertTrue( is_serialized( $case ), "Serialized data: $case" ); + } + } + /** * @ticket 17375 */