add defensive check for ObExprWeightString

This commit is contained in:
AntiTopQuark
2024-04-10 10:15:57 +00:00
committed by ob-robot
parent 6a13cb1f82
commit ce6ee9cf55

View File

@ -43,9 +43,10 @@ int ObExprWeightString::calc_result_typeN(ObExprResType &type,
ObExprTypeCtx &type_ctx) const ObExprTypeCtx &type_ctx) const
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
UNUSED(param_num); CK (5 == param_num);
CK (OB_NOT_NULL(type_ctx.get_session())); CK (OB_NOT_NULL(type_ctx.get_session()));
if (NOT_ROW_DIMENSION != row_dimension_ || ObMaxType == types_stack[0].get_type()) { if (OB_FAIL(ret)) {
} else if (NOT_ROW_DIMENSION != row_dimension_ || ObMaxType == types_stack[0].get_type()) {
ret = OB_ERR_INVALID_TYPE_FOR_OP; ret = OB_ERR_INVALID_TYPE_FOR_OP;
} else { } else {
uint64_t max_length = OB_MAX_VARBINARY_LENGTH; // The maximum length of the result of WEIGHT_STRING() uint64_t max_length = OB_MAX_VARBINARY_LENGTH; // The maximum length of the result of WEIGHT_STRING()
@ -70,6 +71,8 @@ int ObExprWeightString::calc_result_typeN(ObExprResType &type,
} }
ObCollationType collation_type = types_stack[0].get_collation_type(); ObCollationType collation_type = types_stack[0].get_collation_type();
const ObCharsetInfo *cs = ObCharset::get_charset(collation_type); const ObCharsetInfo *cs = ObCharset::get_charset(collation_type);
CK (OB_NOT_NULL(cs));
if (OB_SUCC(ret)) {
if (types_stack[0].get_type() == ObDateTimeType || if (types_stack[0].get_type() == ObDateTimeType ||
types_stack[0].get_type() == ObTimestampType || types_stack[0].get_type() == ObTimestampType ||
types_stack[0].get_type() == ObDateType || types_stack[0].get_type() == ObDateType ||
@ -90,6 +93,7 @@ int ObExprWeightString::calc_result_typeN(ObExprResType &type,
type.set_collation_level(coll_level); type.set_collation_level(coll_level);
type.set_length(max_length); type.set_length(max_length);
} }
}
return ret; return ret;
} }
@ -101,7 +105,11 @@ int ObExprWeightString::eval_weight_string(const ObExpr &expr, ObEvalCtx &ctx, O
ObDatum *nweights_arg = NULL; ObDatum *nweights_arg = NULL;
ObDatum *flags_arg = NULL; ObDatum *flags_arg = NULL;
ObDatum *as_binary_arg = NULL; ObDatum *as_binary_arg = NULL;
if (OB_FAIL(expr.args_[0]->eval(ctx, arg)) || if (OB_ISNULL(expr.args_[0]) || OB_ISNULL(expr.args_[1]) || OB_ISNULL(expr.args_[2]) ||
OB_ISNULL(expr.args_[3]) || OB_ISNULL(expr.args_[4])) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", K(ret));
} else if (OB_FAIL(expr.args_[0]->eval(ctx, arg)) ||
OB_FAIL(expr.args_[1]->eval(ctx, result_length_arg)) || OB_FAIL(expr.args_[1]->eval(ctx, result_length_arg)) ||
OB_FAIL(expr.args_[2]->eval(ctx, nweights_arg)) || OB_FAIL(expr.args_[2]->eval(ctx, nweights_arg)) ||
OB_FAIL(expr.args_[3]->eval(ctx, flags_arg)) || OB_FAIL(expr.args_[3]->eval(ctx, flags_arg)) ||
@ -137,7 +145,9 @@ int ObExprWeightString::eval_weight_string(const ObExpr &expr, ObEvalCtx &ctx, O
} else { } else {
LOG_WARN("Failed to get max allow packet size", K(ret)); LOG_WARN("Failed to get max allow packet size", K(ret));
} }
} } else {
// Get the character set and collation information of the input string // Get the character set and collation information of the input string
ObCollationType collation_type = CS_TYPE_INVALID; ObCollationType collation_type = CS_TYPE_INVALID;
if (as_binary) { if (as_binary) {
@ -146,6 +156,8 @@ int ObExprWeightString::eval_weight_string(const ObExpr &expr, ObEvalCtx &ctx, O
collation_type = expr.args_[0]->datum_meta_.cs_type_; collation_type = expr.args_[0]->datum_meta_.cs_type_;
} }
const ObCharsetInfo *cs = ObCharset::get_charset(collation_type); const ObCharsetInfo *cs = ObCharset::get_charset(collation_type);
CK (OB_NOT_NULL(cs));
if (OB_SUCC(ret)) {
flags = ob_strxfrm_flag_normalize(flags, cs->levels_for_order); flags = ob_strxfrm_flag_normalize(flags, cs->levels_for_order);
// calc the length of result // calc the length of result
size_t frm_length = 0; size_t frm_length = 0;
@ -199,6 +211,8 @@ int ObExprWeightString::eval_weight_string(const ObExpr &expr, ObEvalCtx &ctx, O
} }
} }
} }
}
}
return ret; return ret;
} }