pingcap / mysql-tester

A Golang implementation of MySQL Test Framework
Apache License 2.0
61 stars 62 forks source link

mysql tester crashes when selecting truncated incorrect DECIMAL value #44

Open espresso98 opened 2 years ago

espresso98 commented 2 years ago

When selecting a truncated incorrect value, mysql tester crashes.

select 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 as x;
select 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 + 1 as x;
create table t1 (s varchar(100));
insert into t1 values (0.00000000010000000000000000364321973154977415791655470655996396089904010295867919921875);
drop table t1;
CREATE TABLE t2 (i DECIMAL (30,27));
INSERT INTO t2 VALUES (6.8926822182388193469056146);
DROP TABLE t2;

SET sql_mode="";
CREATE TABLE t (a int);
INSERT INTO t() VALUES(),(),(),();
SELECT
lag(1,96,
-66812354762147309124165421419678600705366236356475480.892682218238819346905614650696)
over()
FROM t;

DROP TABLE t;
SET sql_mode = default;
create table t1 (c1 decimal(64));
insert into t1 values(
89000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);
--error ER_DATA_OUT_OF_RANGE
insert into t1 values(
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 *
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999);
insert into t1 values(1e100);
select * from t1;
drop table t1;

Output is

panic: This branch is not implemented. This is because you are trying to test something specific to TiDB's MyDecimal implementation. It is recommended to do this in TiDB repository.

goroutine 7 [running]:
github.com/pingcap/tidb/parser/test_driver.fixWordCntError(...)
        /Users/youracho/go/pkg/mod/github.com/pingcap/tidb/parser@v0.0.0-20211122065349-4d16aabf900b/test_driver/test_driver_mydecimal.go:36
github.com/pingcap/tidb/parser/test_driver.(*MyDecimal).FromString(0x30, {0xc00042e000, 0x82, 0xc000056d80})
        /Users/youracho/go/pkg/mod/github.com/pingcap/tidb/parser@v0.0.0-20211122065349-4d16aabf900b/test_driver/test_driver_mydecimal.go:226 +0x3db
github.com/pingcap/tidb/parser/test_driver.init.0.func1({0xc0000ee127, 0x82})
        /Users/youracho/go/pkg/mod/github.com/pingcap/tidb/parser@v0.0.0-20211122065349-4d16aabf900b/test_driver/test_driver.go:34 +0x58
github.com/pingcap/tidb/parser.toDecimal({0x144ed58, 0xc000096048}, 0xc0000961a0, {0xc0000ee127, 0x1})
        /Users/youracho/go/pkg/mod/github.com/pingcap/tidb/parser@v0.0.0-20211122065349-4d16aabf900b/yy_parser.go:274 +0x3f
github.com/pingcap/tidb/parser.toInt({0x144ed58, 0xc000096048}, 0xc0000961a0, {0xc0000ee127, 0x82})
        /Users/youracho/go/pkg/mod/github.com/pingcap/tidb/parser@v0.0.0-20211122065349-4d16aabf900b/yy_parser.go:258 +0x150
github.com/pingcap/tidb/parser.(*Scanner).Lex(0xc000096048, 0xc0000961a0)
        /Users/youracho/go/pkg/mod/github.com/pingcap/tidb/parser@v0.0.0-20211122065349-4d16aabf900b/lexer.go:218 +0x3f3
github.com/pingcap/tidb/parser.yylex1({0x144ed58, 0xc000096048}, 0xc0000961a0)
        /Users/youracho/go/pkg/mod/github.com/pingcap/tidb/parser@v0.0.0-20211122065349-4d16aabf900b/parser.go:11023 +0x4a
github.com/pingcap/tidb/parser.yyParse({0x144ed58, 0xc000096048}, 0xc000096000)
        /Users/youracho/go/pkg/mod/github.com/pingcap/tidb/parser@v0.0.0-20211122065349-4d16aabf900b/parser.go:11077 +0x79ef7
github.com/pingcap/tidb/parser.(*Parser).ParseSQL(0xc000096000, {0xc0000ee120, 0x8f}, {0xc0001b1bd0, 0x2, 0x377})
        /Users/youracho/go/pkg/mod/github.com/pingcap/tidb/parser@v0.0.0-20211122065349-4d16aabf900b/yy_parser.go:154 +0x2b3
github.com/pingcap/tidb/parser.(*Parser).Parse(...)
        /Users/youracho/go/pkg/mod/github.com/pingcap/tidb/parser@v0.0.0-20211122065349-4d16aabf900b/yy_parser.go:174
main.(*tester).execute(0xc000090000, {{0xc0000ee120, 0x6}, {0xc0000ee120, 0x8f}, 0x37c, 0x2})
        /Users/youracho/go/pkg/mod/github.com/pingcap/mysql-tester@v0.0.0-20211203024718-0ecb03c9cf5c/src/main.go:638 +0x11b
main.(*tester).Run(0xc000090000)
        /Users/youracho/go/pkg/mod/github.com/pingcap/mysql-tester@v0.0.0-20211203024718-0ecb03c9cf5c/src/main.go:318 +0x645
main.testBatch.Run({0xc00000c1e0, 0x1, 0x0})
        /Users/youracho/go/pkg/mod/github.com/pingcap/mysql-tester@v0.0.0-20211203024718-0ecb03c9cf5c/src/main.go:948 +0xbd
created by main.executeTests
        /Users/youracho/go/pkg/mod/github.com/pingcap/mysql-tester@v0.0.0-20211203024718-0ecb03c9cf5c/src/main.go:978 +0x1b3
tidb-server(PID: 35799) stopped