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

expression: handle tp.flen overflow in to_base64 function (#20947) #21813

Merged
merged 5 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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