Skip to content

Commit

Permalink
expression: handle tp.flen overflow in to_base64 function (#20947) (#…
Browse files Browse the repository at this point in the history
…21813)

Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
ti-srebot authored Jan 25, 2021
1 parent e4526c7 commit d6756cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion expression/builtin_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -3549,7 +3549,7 @@ func (b *builtinToBase64Sig) evalString(row chunk.Row) (d string, isNull bool, e
return "", true, nil
}
if b.tp.Flen == -1 || b.tp.Flen > mysql.MaxBlobWidth {
return "", true, nil
b.tp.Flen = mysql.MaxBlobWidth
}

//encode
Expand Down
3 changes: 1 addition & 2 deletions expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2420,8 +2420,7 @@ func (b *builtinToBase64Sig) vecEvalString(input *chunk.Chunk, result *chunk.Col
result.AppendNull()
continue
} else if b.tp.Flen == -1 || b.tp.Flen > mysql.MaxBlobWidth {
result.AppendNull()
continue
b.tp.Flen = mysql.MaxBlobWidth
}

newStr := base64.StdEncoding.EncodeToString([]byte(str))
Expand Down
13 changes: 13 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7294,6 +7294,19 @@ func (s *testIntegrationSuite) TestIssue17476(c *C) {
tk.MustQuery(`SELECT * FROM (table_int_float_varchar AS tmp3) WHERE (col_varchar_6 AND NULL) IS NULL AND col_int_6=0;`).Check(testkit.Rows("13 0 -0.1 <nil>"))
}

func (s *testIntegrationSuite) TestIssue14349(c *C) {
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists papers;")
tk.MustExec("create table papers(title text, content longtext)")
tk.MustExec("insert into papers values('title', 'content')")
tk.MustQuery(`select to_base64(title), to_base64(content) from papers;`).Check(testkit.Rows("dGl0bGU= Y29udGVudA=="))
tk.MustExec("set tidb_enable_vectorized_expression = 0;")
tk.MustQuery(`select to_base64(title), to_base64(content) from papers;`).Check(testkit.Rows("dGl0bGU= Y29udGVudA=="))
tk.MustExec("set tidb_enable_vectorized_expression = 1;")
}

func (s *testIntegrationSuite) TestIssue20180(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down

0 comments on commit d6756cf

Please sign in to comment.