MDEV-25174 DOUBLE columns do not accept large hex hybrids

Limit only signed integer fields fields to LONGLONG_MAX.
Double and decimal fields do not need this limit, as they
can store integers up to ULONGLONG_MAX without problems.
This commit is contained in:
Alexander Barkov 2024-11-13 09:40:18 +04:00
parent 70dbd63e02
commit 09fe74c7fd
5 changed files with 50 additions and 1 deletions

View file

@ -1283,5 +1283,18 @@ h varchar(16) YES NULL
DROP TABLE t1, t2;
SET sql_mode=DEFAULT;
#
# MDEV-25174 DOUBLE columns do not accept large hex hybrids
#
CREATE TABLE t1 (a DOUBLE);
INSERT INTO t1 VALUES (0x7FFFFFFFFFFFFFFF);
INSERT INTO t1 VALUES (0x8000000000000000);
INSERT INTO t1 VALUES (0xFFFFFFFFFFFFFFFF);
SELECT * FROM t1 ORDER BY a;
a
9.223372036854776e18
9.223372036854776e18
1.8446744073709552e19
DROP TABLE t1;
#
# End of 10.5 tests
#

View file

@ -798,6 +798,17 @@ DROP TABLE t1, t2;
SET sql_mode=DEFAULT;
--echo #
--echo # MDEV-25174 DOUBLE columns do not accept large hex hybrids
--echo #
CREATE TABLE t1 (a DOUBLE);
INSERT INTO t1 VALUES (0x7FFFFFFFFFFFFFFF);
INSERT INTO t1 VALUES (0x8000000000000000);
INSERT INTO t1 VALUES (0xFFFFFFFFFFFFFFFF);
SELECT * FROM t1 ORDER BY a;
DROP TABLE t1;
--echo #
--echo # End of 10.5 tests
--echo #

View file

@ -2873,5 +2873,18 @@ h varchar(16) YES NULL
DROP TABLE t1, t2;
SET sql_mode=DEFAULT;
#
# MDEV-25174 DOUBLE columns do not accept large hex hybrids
#
CREATE TABLE t1 (a DECIMAL(30,0));
INSERT INTO t1 VALUES (0x7FFFFFFFFFFFFFFF);
INSERT INTO t1 VALUES (0x8000000000000000);
INSERT INTO t1 VALUES (0xFFFFFFFFFFFFFFFF);
SELECT * FROM t1 ORDER BY a;
a
9223372036854775807
9223372036854775808
18446744073709551615
DROP TABLE t1;
#
# End of 10.5 tests
#

View file

@ -2050,6 +2050,17 @@ DROP TABLE t1, t2;
SET sql_mode=DEFAULT;
--echo #
--echo # MDEV-25174 DOUBLE columns do not accept large hex hybrids
--echo #
CREATE TABLE t1 (a DECIMAL(30,0));
INSERT INTO t1 VALUES (0x7FFFFFFFFFFFFFFF);
INSERT INTO t1 VALUES (0x8000000000000000);
INSERT INTO t1 VALUES (0xFFFFFFFFFFFFFFFF);
SELECT * FROM t1 ORDER BY a;
DROP TABLE t1;
--echo #
--echo # End of 10.5 tests
--echo #

View file

@ -1339,7 +1339,8 @@ int Field::store_hex_hybrid(const char *str, size_t length)
goto warn;
}
nr= (ulonglong) longlong_from_hex_hybrid(str, length);
if ((length == 8) && !(flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX))
if ((length == 8) && cmp_type()== INT_RESULT &&
!(flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX))
{
nr= LONGLONG_MAX;
goto warn;