Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error report: 'runtime error: index out of range [1] with length 1' when using aes_decrypt sometimes #43076

Closed
lcwangchao opened this issue Apr 14, 2023 · 3 comments

Comments

@lcwangchao
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table tx(s1 blob, s2 blob);
insert into tx values (aes_encrypt('a', 'b'), aes_encrypt('c', 'd'));
select * from tx where aes_decrypt(s1, 'b')='' and aes_decrypt(s2, 'd')='';

2. What did you expect to see? (Required)

no error

3. What did you see instead (Required)

TiDB root@127.0.0.1:test> select * from tx where aes_decrypt(s1, 'b')='' and aes_decrypt(s2, 'd')='';
(1105, 'runtime error: index out of range [1] with length 1')

4. What is your TiDB version? (Required)

TiDB root@127.0.0.1:test> select tidb_version();
+-----------------------------------------------------------+
| tidb_version()                                            |
+-----------------------------------------------------------+
| Release Version: v7.1.0-alpha                             |
| Edition: Community                                        |
| Git Commit Hash: c282c9c94276ef698f93d6aa89df7dde16f6f479 |
| Git Branch: heads/refs/tags/v7.1.0-alpha                  |
| UTC Build Time: 2023-04-10 14:26:56                       |
| GoVersion: go1.20.3                                       |
| Race Enabled: false                                       |
| TiKV Min Version: 6.2.0-alpha                             |
| Check Table Before Drop: false                            |
| Store: tikv                                               |
+-----------------------------------------------------------+
1 row in set
@lcwangchao lcwangchao added type/bug The issue is confirmed as a bug. sig/execution SIG execution severity/major labels Apr 14, 2023
@ti-chi-bot ti-chi-bot added may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 labels Apr 14, 2023
@lcwangchao lcwangchao added affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 and removed may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 affects-4.0 This bug affects 4.0.x versions. labels Apr 14, 2023
@lcwangchao lcwangchao added affects-6.1 and removed affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 labels Apr 14, 2023
@lcwangchao
Copy link
Collaborator Author

The panic stack is here

[2023/04/14 21:17:19.125 +08:00] [INFO] [conn.go:1154] ["command dispatched failed"] [conn=2199023255957] [connInfo="id:2199023255957, addr:127.0.0.1:58798 status:10, collation:utf8_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="select * from tx where aes_decrypt(s1, 'b')='' and aes_decrypt(s2, 'd')=''"] [txn_mode=PESSIMISTIC] [timestamp=440789430986604544] [err="runtime error: index out of range [1] with length 1\ngithub.com/pingcap/tidb/executor.(*recordSet).Next.func1\n\t/Users/wangchao/Code/pingcap/tidb/executor/adapter.go:146\nruntime.gopanic\n\t/Users/wangchao/.gvm/gos/go1.20.2/src/runtime/panic.go:890\nruntime.goPanicIndex\n\t/Users/wangchao/.gvm/gos/go1.20.2/src/runtime/panic.go:113\ngithub.com/pingcap/tidb/util/chunk.(*Column).GetBytes\n\t/Users/wangchao/Code/pingcap/tidb/util/chunk/column.go:591\ngithub.com/pingcap/tidb/expression.(*builtinAesDecryptSig).vecEvalString\n\t/Users/wangchao/Code/pingcap/tidb/expression/builtin_encryption_vec.go:77\ngithub.com/pingcap/tidb/expression.(*ScalarFunction).VecEvalString\n\t/Users/wangchao/Code/pingcap/tidb/expression/scalar_function.go:58\ngithub.com/pingcap/tidb/expression.(*builtinEQStringSig).vecEvalInt\n\t/Users/wangchao/Code/pingcap/tidb/expression/builtin_compare_vec_generated.go:1003\ngithub.com/pingcap/tidb/expression.(*ScalarFunction).VecEvalInt\n\t/Users/wangchao/Code/pingcap/tidb/expression/scalar_function.go:48\ngithub.com/pingcap/tidb/expression.EvalExpr\n\t/Users/wangchao/Code/pingcap/tidb/expression/expression.go:574\ngithub.com/pingcap/tidb/expression.VecEvalBool\n\t/Users/wangchao/Code/pingcap/tidb/expression/expression.go:369\ngithub.com/pingcap/tidb/expression.vectorizedFilter\n\t/Users/wangchao/Code/pingcap/tidb/expression/chunk_executor.go:489\ngithub.com/pingcap/tidb/expression.VectorizedFilterConsiderNull\n\t/Users/wangchao/Code/pingcap/tidb/expression/chunk_executor.go:401\ngithub.com/pingcap/tidb/expression.VectorizedFilter\n\t/Users/wangchao/Code/pingcap/tidb/expression/chunk_executor.go:379\ngithub.com/pingcap/tidb/executor.(*SelectionExec).Next\n\t/Users/wangchao/Code/pingcap/tidb/executor/executor.go:1675\ngithub.com/pingcap/tidb/executor.Next\n\t/Users/wangchao/Code/pingcap/tidb/executor/executor.go:326\ngithub.com/pingcap/tidb/executor.(*ExecStmt).next\n\t/Users/wangchao/Code/pingcap/tidb/executor/adapter.go:1194\ngithub.com/pingcap/tidb/executor.(*recordSet).Next\n\t/Users/wangchao/Code/pingcap/tidb/executor/adapter.go:150\ngithub.com/pingcap/tidb/server.(*tidbResultSet).Next\n\t/Users/wangchao/Code/pingcap/tidb/server/driver_tidb.go:428\ngithub.com/pingcap/tidb/server.(*clientConn).writeChunks\n\t/Users/wangchao/Code/pingcap/tidb/server/conn.go:2281\ngithub.com/pingcap/tidb/server.(*clientConn).writeResultSet\n\t/Users/wangchao/Code/pingcap/tidb/server/conn.go:2224\ngithub.com/pingcap/tidb/server.(*clientConn).handleStmt\n\t/Users/wangchao/Code/pingcap/tidb/server/conn.go:2097\ngithub.com/pingcap/tidb/server.(*clientConn).handleQuery\n\t/Users/wangchao/Code/pingcap/tidb/server/conn.go:1864\ngithub.com/pingcap/tidb/server.(*clientConn).dispatch\n\t/Users/wangchao/Code/pingcap/tidb/server/conn.go:1342\ngithub.com/pingcap/tidb/server.(*clientConn).Run\n\t/Users/wangchao/Code/pingcap/tidb/server/conn.go:1123\ngithub.com/pingcap/tidb/server.(*Server).onConn\n\t/Users/wangchao/Code/pingcap/tidb/server/server.go:677\nruntime.goexit\n\t/Users/wangchao/.gvm/gos/go1.20.2/src/runtime/asm_arm64.s:1172"]

@lcwangchao
Copy link
Collaborator Author

It panics here:

key = encrypt.DeriveKeyMySQL(keyBuf.GetBytes(0), b.keySize)

The vecEvalString does handle the case input.NumRows() == 0

@lcwangchao
Copy link
Collaborator Author

dup with #43063

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants