Skip to content

Commit dc21fcb

Browse files
authored
[fix](string function) fix coredump cause by not supported charset of convert function (#17032)
sql select convert('a' using utf8) cause coredump of BE: Thread 338 "FragmentMgrThre" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7f0b2c21a700 (LWP 2865259)] 0x00007fff04f8a015 in __gconv_close () from /lib64/libc.so.6 (gdb) bt #0 0x00007fff04f8a015 in __gconv_close () from /lib64/libc.so.6 #1 0x00007fff04f899e3 in iconv_close () from /lib64/libc.so.6 #2 0x000055556f92f5a7 in doris::vectorized::FunctionConvertTo::close (this=0x606003f28f50, context=0x6020039fe710, scope=doris_udf::FunctionContext::THREAD_LOCAL) at /mnt/disk2/tengjianping/doris-1.2/be/src/vec/functions/function_string.h:2442 #3 0x000055556db0598d in doris::vectorized::DefaultFunction::close (this=0x607000748f00, context=0x6020039fe710, scope=doris_udf::FunctionContext::THREAD_LOCAL) at /mnt/disk2/tengjianping/doris-1.2/be/src/vec/functions/function.h:524 #4 0x000055556da00b66 in doris::vectorized::VExpr::close_function_context (this=0x619004ca1d80, context=0x606003fad300, scope=doris_udf::FunctionContext::FRAGMENT_LOCAL, function=...) at /mnt/disk2/tengjianping/doris-1.2/be/src/vec/exprs/vexpr.cpp:373 #5 0x000055556da16455 in doris::vectorized::VectorizedFnCall::close (this=0x619004ca1d80, state=0x61c00026c880, context=0x606003fad300, scope=doris_udf::FunctionContext::FRAGMENT_LOCAL) at /mnt/disk2/tengjianping/doris-1.2/be/src/vec/exprs/vectorized_fn_call.cpp:92 #6 0x000055556da26afd in doris::vectorized::VExprContext::close (this=0x606003fad300, state=0x61c00026c880) at /mnt/disk2/tengjianping/doris-1.2/be/src/vec/exprs/vexpr_context.cpp:72 #7 0x000055556d9fcff1 in doris::vectorized::VExpr::close (ctxs=..., state=0x61c00026c880) at /mnt/disk2/tengjianping/doris-1.2/be/src/vec/exprs/vexpr.cpp:242 #8 0x000055556aa32c9a in doris::vectorized::VSortExecExprs::close (this=0x618000345f00, state=0x61c00026c880) at /mnt/disk2/tengjianping/doris-1.2/be/src/vec/common/sort/vsort_exec_exprs.cpp:77 #9 0x000055556aa26dae in doris::vectorized::VSortNode::close (this=0x618000345c80, state=0x61c00026c880) at /mnt/disk2/tengjianping/doris-1.2/be/src/vec/exec/vsort_node.cpp:129 #10 0x000055556794b5ef in doris::PlanFragmentExecutor::close (this=0x6170005a35f0) at /mnt/disk2/tengjianping/doris-1.2/be/src/runtime/plan_fragment_executor.cpp:676 #11 0x00005555678ce1fb in doris::FragmentExecState::execute (this=0x6170005a3580) at /mnt/disk2/tengjianping/doris-1.2/be/src/runtime/fragment_mgr.cpp:258 #12 0x00005555678d6633 in doris::FragmentMgr::_exec_actual(std::shared_ptr<doris::FragmentExecState>, std::function<void (doris::PlanFragmentExecutor*)>) (this=0x627000003900, exec_state=..., cb=...) at /mnt/disk2/tengjianping/doris-1.2/be/src/runtime/fragment_mgr.cpp:497 #13 0x00005555678d8aa3 in operator() (__closure=0x60800014cda0) at /mnt/disk2/tengjianping/doris-1.2/be/src/runtime/fragment_mgr.cpp:721
1 parent e294248 commit dc21fcb

3 files changed

Lines changed: 40 additions & 7 deletions

File tree

‎be/src/vec/functions/function_string.h‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,15 +2387,15 @@ class FunctionConvertTo : public IFunction {
23872387
const auto& character_data = context->get_constant_col(1)->column_ptr->get_data_at(0);
23882388
if (doris::iequal(character_data.to_string(), "gbk")) {
23892389
iconv_t cd = iconv_open("gb2312", "utf-8");
2390-
if (cd == nullptr) {
2391-
return Status::RuntimeError("function {} is convert to gbk failed in iconv_open",
2390+
if (cd == (iconv_t)-1) {
2391+
LOG(WARNING) << "iconv_open error: " << strerror(errno);
2392+
return Status::RuntimeError("function {} converting to gbk failed in iconv_open",
23922393
get_name());
23932394
}
23942395
context->set_function_state(scope, cd);
23952396
} else {
2396-
return Status::RuntimeError(
2397-
"Illegal second argument column of function convert. now only support "
2398-
"convert to character set of gbk");
2397+
return Status::RuntimeError("Not supported: convert to character set " +
2398+
character_data.to_string());
23992399
}
24002400

24012401
return Status::OK();
@@ -2425,7 +2425,8 @@ class FunctionConvertTo : public IFunction {
24252425
char* in = const_cast<char*>(value_data);
24262426
out_len = in_len;
24272427
if (iconv(cd, &in, &in_len, &out, &out_len) == -1) {
2428-
return Status::RuntimeError("function {} is convert to gbk failed in iconv",
2428+
LOG(WARNING) << "iconv failed, error: " << strerror(errno);
2429+
return Status::RuntimeError("function {} converting to gbk failed in iconv",
24292430
get_name());
24302431
} else {
24312432
res_offset[i] = res_chars.size();
@@ -2439,7 +2440,9 @@ class FunctionConvertTo : public IFunction {
24392440
if (scope == FunctionContext::THREAD_LOCAL) {
24402441
iconv_t cd = reinterpret_cast<iconv_t>(
24412442
context->get_function_state(FunctionContext::THREAD_LOCAL));
2442-
iconv_close(cd);
2443+
if (cd) {
2444+
iconv_close(cd);
2445+
}
24432446
context->set_function_state(FunctionContext::THREAD_LOCAL, nullptr);
24442447
}
24452448
return Status::OK();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !convert_const_to_gbk --
3+
a ˿�
4+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("test_convert") {
19+
test {
20+
sql "select convert('a' using utf8);"
21+
exception "errCode = 2, detailMessage = Not supported"
22+
}
23+
24+
qt_convert_const_to_gbk """select convert("a" using gbk), convert("丝" using gbk);"""
25+
}
26+

0 commit comments

Comments
 (0)