Skip to content

Commit

Permalink
expression: fix index out of range for AES_DECRYPT (#43086) (#43111)
Browse files Browse the repository at this point in the history
* This is an automated cherry-pick of #43086

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>

* fix conflict

---------

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Co-authored-by: 王超 <cclcwangchao@hotmail.com>
  • Loading branch information
ti-chi-bot and lcwangchao authored Apr 23, 2023
1 parent 29116c0 commit 31d682c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions expression/builtin_encryption_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func (b *builtinAesDecryptSig) vectorized() bool {

func (b *builtinAesDecryptSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
if n == 0 {
// If chunk has 0 rows, just return an empty value. So we can simplify codes below it by ignoring 0 row case.
result.Reset(types.ETString)
return nil
}

strBuf, err := b.bufAllocator.get()
if err != nil {
return err
Expand Down
10 changes: 10 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7900,3 +7900,13 @@ func TestIssue39146(t *testing.T) {
tk.MustExec("set @@tidb_enable_vectorized_expression = off;")
tk.MustQuery(`select str_to_date(substr(dest,1,6),'%H%i%s') from sun;`).Check(testkit.Rows("20:23:10"))
}

func TestAesDecryptionVecEvalWithZeroChunk(t *testing.T) {
// see issue: https://github.com/pingcap/tidb/issues/43063
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table test (name1 blob,name2 blob)")
tk.MustExec("insert into test values(aes_encrypt('a', 'x'), aes_encrypt('b', 'x'))")
tk.MustQuery("SELECT * FROM test WHERE CAST(AES_DECRYPT(name1, 'x') AS CHAR) = '00' AND CAST(AES_DECRYPT(name2, 'x') AS CHAR) = '1'").Check(testkit.Rows())
}

0 comments on commit 31d682c

Please sign in to comment.