Open r33s3n6 opened 5 months ago
Can't reproduce it, it will report error like
mysql> SELECT
-> rpad(
-> cast(ref_0.c_zllrsddn96 as char),
-> 33,
-> cast(unhex(
-> cast(case when (NOT NOT(cast( (cast(null as char) >= 'g7ru0xq_') as unsigned))) then ref_0.c_zllrsddn96 else ref_0.c_zllrsddn96 end
-> as char)) as char)) as c4
-> FROM
-> t_u6z6v6m3u as ref_0;
ERROR 3854 (HY000): Cannot convert string '\xA6\xD0' from binary to utf8
Seems that when we are using MySQL ODBC connector, the error can be triggered:
[2024/06/07 05:14:30.316 +00:00] [ERROR] [projection.go:468] ["projection executor panicked"] [error="runtime error: slice bounds out of range [:33] with capacity 32"] [stack="github.com/pingcap/tidb/pkg/executor.recoveryProjection\n\t/workspace/source/tidb/pkg/executor/projection.go:468\ngithub.com/pingcap/tidb/pkg/executor.(*projectionWorker).run.func1\n\t/workspace/source/tidb/pkg/executor/projection.go:435\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:914\nruntime.goPanicSliceAcap\n\t/usr/local/go/src/runtime/panic.go:140\ngithub.com/pingcap/tidb/pkg/expression.(*builtinRpadUTF8Sig).vecEvalString\n\t/workspace/source/tidb/pkg/expression/builtin_string_vec.go:2630\ngithub.com/pingcap/tidb/pkg/expression.(*ScalarFunction).VecEvalString\n\t/workspace/source/tidb/pkg/expression/scalar_function.go:72\ngithub.com/pingcap/tidb/pkg/expression.evalOneVec\n\t/workspace/source/tidb/pkg/expression/chunk_executor.go:172\ngithub.com/pingcap/tidb/pkg/expression.(*defaultEvaluator).run\n\t/workspace/source/tidb/pkg/expression/evaluator.go:52\ngithub.com/pingcap/tidb/pkg/expression.(*EvaluatorSuite).Run\n\t/workspace/source/tidb/pkg/expression/evaluator.go:124\ngithub.com/pingcap/tidb/pkg/executor.(*projectionWorker).run\n\t/workspace/source/tidb/pkg/executor/projection.go:451"]
[2024/06/07 05:14:30.318 +00:00] [INFO] [conn.go:1151] ["command dispatched failed"] [conn=1776304932] [session_alias=] [connInfo="id:1776304932, addr:10.1.2.1:50598 status:10, collation:utf8mb4_0900_ai_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="SELECT rpad( cast(ref_0.c_zllrsddn96 as char), 33, cast(unhex( cast(case when (NOT NOT(cast( (cast(null as char) >= 'g7ru0xq_') as unsigned))) then ref_0.c_zllrsddn96 else ref_0.c_zllrsddn96 end as char)) as char)) as c4 FROM t_u6z6v6m3u as ref_0;"] [txn_mode=PESSIMISTIC] [timestamp=450294518978707470] [err="runtime error: slice bounds out of range [:33] with capacity 32\ngithub.com/pingcap/errors.AddStack\n\t/root/go/pkg/mod/github.com/pingcap/errors@v0.11.5-0.20240318064555-6bd07397691f/errors.go:178\ngithub.com/pingcap/errors.Trace\n\t/root/go/pkg/mod/github.com/pingcap/errors@v0.11.5-0.20240318064555-6bd07397691f/juju_adaptor.go:15\ngithub.com/pingcap/tidb/pkg/util.GetRecoverError\n\t/workspace/source/tidb/pkg/util/util.go:304\ngithub.com/pingcap/tidb/pkg/executor.recoveryProjection\n\t/workspace/source/tidb/pkg/executor/projection.go:466\ngithub.com/pingcap/tidb/pkg/executor.(*projectionWorker).run.func1\n\t/workspace/source/tidb/pkg/executor/projection.go:435\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:914\nruntime.goPanicSliceAcap\n\t/usr/local/go/src/runtime/panic.go:140\ngithub.com/pingcap/tidb/pkg/expression.(*builtinRpadUTF8Sig).vecEvalString\n\t/workspace/source/tidb/pkg/expression/builtin_string_vec.go:2630\ngithub.com/pingcap/tidb/pkg/expression.(*ScalarFunction).VecEvalString\n\t/workspace/source/tidb/pkg/expression/scalar_function.go:72\ngithub.com/pingcap/tidb/pkg/expression.evalOneVec\n\t/workspace/source/tidb/pkg/expression/chunk_executor.go:172\ngithub.com/pingcap/tidb/pkg/expression.(*defaultEvaluator).run\n\t/workspace/source/tidb/pkg/expression/evaluator.go:52\ngithub.com/pingcap/tidb/pkg/expression.(*EvaluatorSuite).Run\n\t/workspace/source/tidb/pkg/expression/evaluator.go:124\ngithub.com/pingcap/tidb/pkg/executor.(*projectionWorker).run\n\t/workspace/source/tidb/pkg/executor/projection.go:451\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1650"]
But when we are using MySQL shell, it just shows Cannot convert string '\xA6\xD0' from binary to utf8
:
[2024/06/07 05:13:29.533 +00:00] [INFO] [conn.go:1151] ["command dispatched failed"] [conn=1776304908] [session_alias=] [connInfo="id:1776304908, addr:10.1.2.1:52446 status:10, collation:utf8mb4_0900_ai_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="SELECT rpad( cast(ref_0.c_zllrsddn96 as char), 33, cast(unhex( cast(case when (NOT NOT(cast( (cast(null as char) >= 'g7ru0xq_') as unsigned))) then ref_0.c_zllrsddn96 else ref_0.c_zllrsddn96 end as char)) as char)) as c4 FROM t_u6z6v6m3u as ref_0"] [txn_mode=PESSIMISTIC] [timestamp=450294503053459457] [err="[expression:3854]Cannot convert string '\\xA6\\xD0' from binary to utf8mb4\ngithub.com/pingcap/errors.AddStack\n\t/root/go/pkg/mod/github.com/pingcap/errors@v0.11.5-0.20240318064555-6bd07397691f/errors.go:178\ngithub.com/pingcap/errors.(*Error).GenWithStackByArgs\n\t/root/go/pkg/mod/github.com/pingcap/errors@v0.11.5-0.20240318064555-6bd07397691f/normalize.go:175\ngithub.com/pingcap/tidb/pkg/expression.(*builtinInternalFromBinarySig).vecEvalString\n\t/workspace/source/tidb/pkg/expression/builtin_convert_charset.go:228\ngithub.com/pingcap/tidb/pkg/expression.(*ScalarFunction).VecEvalString\n\t/workspace/source/tidb/pkg/expression/scalar_function.go:72\ngithub.com/pingcap/tidb/pkg/expression.(*builtinCastStringAsStringSig).vecEvalString\n\t/workspace/source/tidb/pkg/expression/builtin_cast_vec.go:1919\ngithub.com/pingcap/tidb/pkg/expression.(*ScalarFunction).VecEvalString\n\t/workspace/source/tidb/pkg/expression/scalar_function.go:72\ngithub.com/pingcap/tidb/pkg/expression.(*builtinRpadUTF8Sig).vecEvalString\n\t/workspace/source/tidb/pkg/expression/builtin_string_vec.go:2593\ngithub.com/pingcap/tidb/pkg/expression.(*ScalarFunction).VecEvalString\n\t/workspace/source/tidb/pkg/expression/scalar_function.go:72\ngithub.com/pingcap/tidb/pkg/expression.evalOneVec\n\t/workspace/source/tidb/pkg/expression/chunk_executor.go:172\ngithub.com/pingcap/tidb/pkg/expression.(*defaultEvaluator).run\n\t/workspace/source/tidb/pkg/expression/evaluator.go:52\ngithub.com/pingcap/tidb/pkg/expression.(*EvaluatorSuite).Run\n\t/workspace/source/tidb/pkg/expression/evaluator.go:124\ngithub.com/pingcap/tidb/pkg/executor.(*projectionWorker).run\n\t/workspace/source/tidb/pkg/executor/projection.go:451\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1650"]
There are slight differences in stack trace, the first one:
...
github.com/pingcap/tidb/pkg/expression.(*builtinRpadUTF8Sig).vecEvalString
/workspace/source/tidb/pkg/expression/builtin_string_vec.go:2630
...
the second one:
...
github.com/pingcap/tidb/pkg/expression.(*ScalarFunction).VecEvalString
/workspace/source/tidb/pkg/expression/scalar_function.go:72
github.com/pingcap/tidb/pkg/expression.(*builtinRpadUTF8Sig).vecEvalString
/workspace/source/tidb/pkg/expression/builtin_string_vec.go:2593
...
Release Version: v8.2.0-alpha-216-gfe5858b
Edition: Community
Git Commit Hash: fe5858b00cd63808ac414c6e102a353778b0aaa7
Git Branch: HEAD
UTC Build Time: 2024-05-23 01:44:42
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv
Change the tag to 'sig-execution' since it is related to expression evaluation.
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
Expect no crashes
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
We are the BASS team from the School of Cyber Science and Technology at Beihang University. Our main focus is on system software security, operating systems, and program analysis research, as well as the development of automated program testing frameworks for detecting software defects. Using our self-developed database vulnerability testing tool, we have identified the above-mentioned vulnerabilities in TiDB that may lead to database crashes.