Skip to content

Commit

Permalink
expression: fix index out of range for AES_DECRYPT (#43086) (#43110)
Browse files Browse the repository at this point in the history
close #43063
  • Loading branch information
ti-chi-bot authored Apr 21, 2023
1 parent 6ee75cd commit 4cbee73
Show file tree
Hide file tree
Showing 2 changed files with 17 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 @@ -41,6 +41,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
11 changes: 11 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7444,3 +7444,14 @@ 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, clean := testkit.CreateMockStore(t)
defer clean()
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 4cbee73

Please sign in to comment.