Skip to content

Commit 4b67ff3

Browse files
MDEV-30705: JSON_SCHEMA_VALID: schema with multipleOf for big value
always return 1 Analysis: Implementation used double to store value. longlong is better choice Fix: Use longlong for multiple_of and the value to store it and num_flag to check for decimals.
1 parent 2c4c7c8 commit 4b67ff3

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

mysql-test/main/func_json.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4634,4 +4634,19 @@ ERROR HY000: Invalid value for keyword maxLength
46344634
SET @schema= '{ "items" : ["str1"]}';
46354635
SELECT JSON_SCHEMA_VALID(@schema, '[]');
46364636
ERROR HY000: Invalid value for keyword items
4637+
#
4638+
# MDEV-30705: JSON_SCHEMA_VALID: schema with multipleOf for big value always return 1
4639+
#
4640+
SET @schema = '{
4641+
"multipleOf": 2
4642+
}';
4643+
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000001');
4644+
JSON_SCHEMA_VALID(@schema, '9007900000000001')
4645+
0
4646+
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000060');
4647+
JSON_SCHEMA_VALID(@schema, '9007900000000060')
4648+
1
4649+
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000061');
4650+
JSON_SCHEMA_VALID(@schema, '9007900000000061')
4651+
0
46374652
# End of 11.1 test

mysql-test/main/func_json.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,4 +3533,15 @@ SET @schema= '{ "items" : ["str1"]}';
35333533
SELECT JSON_SCHEMA_VALID(@schema, '[]');
35343534

35353535

3536+
--echo #
3537+
--echo # MDEV-30705: JSON_SCHEMA_VALID: schema with multipleOf for big value always return 1
3538+
--echo #
3539+
SET @schema = '{
3540+
"multipleOf": 2
3541+
}';
3542+
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000001');
3543+
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000060');
3544+
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000061');
3545+
3546+
35363547
--echo # End of 11.1 test

sql/json_schema.cc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -771,13 +771,25 @@ bool Json_schema_multiple_of::validate(const json_engine_t *je,
771771

772772
if (je->value_type != JSON_VALUE_NUMBER)
773773
return false;
774+
if (je->num_flags & JSON_NUM_FRAC_PART)
775+
return true;
774776

777+
<<<<<<< HEAD
775778
double val= je->s.cs->strntod((char *) je->value,
776779
je->value_len, &end, &err);
777780
double temp= val / multiple_of;
778781
bool res= (temp - (long long int)temp) == 0;
782+
||||||| parent of 628ce9d4f44... MDEV-30705: JSON_SCHEMA_VALID: schema with multipleOf for big value
783+
double val= je->s.cs->strntod((char *) je->value,
784+
je->value_len, &end, &err);
785+
double temp= val / this->value;
786+
bool res= (temp - (long long int)temp) == 0;
787+
=======
788+
longlong val= je->s.cs->strntoll((char *) je->value,
789+
je->value_len, 10, &end, &err);
790+
>>>>>>> 628ce9d4f44... MDEV-30705: JSON_SCHEMA_VALID: schema with multipleOf for big value
779791

780-
return !res;
792+
return val % multiple_of;
781793
}
782794

783795
bool Json_schema_multiple_of::handle_keyword(THD *thd, json_engine_t *je,
@@ -789,19 +801,16 @@ bool Json_schema_multiple_of::handle_keyword(THD *thd, json_engine_t *je,
789801
int err= 0;
790802
char *end;
791803

792-
if (je->value_type != JSON_VALUE_NUMBER)
804+
if (je->value_type != JSON_VALUE_NUMBER || (je->num_flags & JSON_NUM_FRAC_PART))
793805
{
794806
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "multipleOf");
795807
return true;
796808
}
797809

798-
double val= je->s.cs->strntod((char *) je->value,
799-
je->value_len, &end, &err);
810+
longlong val= je->s.cs->strntoll((char *) je->value,
811+
je->value_len, 10, &end, &err);
800812
if (val <= 0)
801-
{
802813
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "multipleOf");
803-
return true;
804-
}
805814
multiple_of= val;
806815

807816
return false;

sql/json_schema.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ class Json_schema_minimum : public Json_schema_keyword
228228
class Json_schema_multiple_of : public Json_schema_keyword
229229
{
230230
private:
231-
double multiple_of;
231+
longlong multiple_of;
232+
232233
public:
233234
bool validate(const json_engine_t *je, const uchar *k_start= NULL,
234235
const uchar *k_end= NULL) override;

0 commit comments

Comments
 (0)