Skip to content

Commit 28c3531

Browse files
committed
Bug#25518504: SOME BIG NUMBERS IN JSON DOCUMENTS BECOME ZERO
Some very large floating-point numbers were silently changed to zero in JSON documents. The problem was that RapidJSON returned positive or negative infinity for these values instead of raising an error, and non-finite values were not expected in the MySQL code. Fix: Make Rapid_json_handler::Double() check if the double value is finite, and raise an error if it is not. Change-Id: I753f0d4a7a92020a18998ea9ef1d5746e40d0af6
1 parent 0233670 commit 28c3531

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

mysql-test/suite/json/r/json_no_table.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,3 +3338,14 @@ c1 c2 c3 c4
33383338
SELECT SUM(CAST('5.45' AS JSON));
33393339
SUM(CAST('5.45' AS JSON))
33403340
5.45
3341+
#
3342+
# Bug#25518504: SOME BIG NUMBERS IN JSON DOCUMENTS BECOME ZERO
3343+
#
3344+
SELECT CAST('2e308' AS JSON);
3345+
ERROR 22032: Invalid JSON text in argument 1 to function cast_as_json: "Terminate parsing due to Handler error." at position 0.
3346+
SELECT CAST('-2e308' AS JSON);
3347+
ERROR 22032: Invalid JSON text in argument 1 to function cast_as_json: "Terminate parsing due to Handler error." at position 0.
3348+
SELECT CAST('2e309' AS JSON);
3349+
ERROR 22032: Invalid JSON text in argument 1 to function cast_as_json: "Number too big to be stored in double." at position 0.
3350+
SELECT CAST('-2e309' AS JSON);
3351+
ERROR 22032: Invalid JSON text in argument 1 to function cast_as_json: "Number too big to be stored in double." at position 0.

mysql-test/suite/json/t/json_no_table.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,3 +2334,17 @@ SELECT JSON_SEARCH('["a", "a"]', CAST('one' AS CHAR CHARSET utf16), 'a') AS c1,
23342334
--echo # Bug#25530204: THE RESULT OF SUM ON JSON_EXTRACT LOST THE DECIMAL PART
23352335
--echo #
23362336
SELECT SUM(CAST('5.45' AS JSON));
2337+
2338+
--echo #
2339+
--echo # Bug#25518504: SOME BIG NUMBERS IN JSON DOCUMENTS BECOME ZERO
2340+
--echo #
2341+
# These statements returned zero instead of raising an error.
2342+
--error ER_INVALID_JSON_TEXT_IN_PARAM
2343+
SELECT CAST('2e308' AS JSON);
2344+
--error ER_INVALID_JSON_TEXT_IN_PARAM
2345+
SELECT CAST('-2e308' AS JSON);
2346+
# These statements correctly returned an error even before the fix.
2347+
--error ER_INVALID_JSON_TEXT_IN_PARAM
2348+
SELECT CAST('2e309' AS JSON);
2349+
--error ER_INVALID_JSON_TEXT_IN_PARAM
2350+
SELECT CAST('-2e309' AS JSON);

sql/json_dom.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "json_dom.h"
1717

18+
#include <cmath> // std::isfinite
1819
#include <errno.h>
1920
#include <limits.h>
2021
#include <math.h>
@@ -574,6 +575,12 @@ class Rapid_json_handler
574575
bool Double(double d)
575576
{
576577
DUMP_CALLBACK("double", state);
578+
/*
579+
We only accept finite values. RapidJSON normally stops non-finite values
580+
from getting here, but sometimes +/-inf values could end up here anyway.
581+
*/
582+
if (!std::isfinite(d))
583+
return false;
577584
return seeing_value(new (std::nothrow) Json_double(d));
578585
}
579586

0 commit comments

Comments
 (0)