From bcf3d94b1d8cfbf6bfd37a9fad77cfec5aa775f8 Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 19 Jul 2023 08:12:18 +0000 Subject: [PATCH] fix st_distance stack overflow --- deps/oblib/src/lib/geo/ob_geo_func_distance.cpp | 5 ++--- src/sql/engine/expr/ob_expr_st_distance.cpp | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/deps/oblib/src/lib/geo/ob_geo_func_distance.cpp b/deps/oblib/src/lib/geo/ob_geo_func_distance.cpp index ba31404483..fbd5f57637 100644 --- a/deps/oblib/src/lib/geo/ob_geo_func_distance.cpp +++ b/deps/oblib/src/lib/geo/ob_geo_func_distance.cpp @@ -125,7 +125,6 @@ private: { INIT_SUCC(ret); common::ObIAllocator *allocator = context.get_allocator(); - typename CollectonType::iterator iter; double min_dist = std::numeric_limits::infinity(); double temp_res = min_dist; @@ -134,7 +133,7 @@ private: LOG_WARN("Null allocator", K(ret)); } else if (g1->type() == ObGeoType::GEOMETRYCOLLECTION) { const CollectonType *geo1 = reinterpret_cast(g1->val()); - iter = geo1->begin(); + typename CollectonType::iterator iter = geo1->begin(); for (; iter != geo1->end() && OB_SUCC(ret); iter++) { typename CollectonType::const_pointer sub_ptr = iter.operator->(); ObGeoType sub_type = geo1->get_sub_type(sub_ptr); @@ -155,7 +154,7 @@ private: } } else if (g2->type() == ObGeoType::GEOMETRYCOLLECTION) { const CollectonType *geo2 = reinterpret_cast(g2->val()); - iter = geo2->begin(); + typename CollectonType::iterator iter = geo2->begin(); for (; iter != geo2->end() && OB_SUCC(ret); iter++) { typename CollectonType::const_pointer sub_ptr = iter.operator->(); ObGeoType sub_type = geo2->get_sub_type(sub_ptr); diff --git a/src/sql/engine/expr/ob_expr_st_distance.cpp b/src/sql/engine/expr/ob_expr_st_distance.cpp index be766d1f4c..553e1694a5 100644 --- a/src/sql/engine/expr/ob_expr_st_distance.cpp +++ b/src/sql/engine/expr/ob_expr_st_distance.cpp @@ -188,10 +188,8 @@ int ObExprSTDistance::eval_st_distance(const ObExpr &expr, ObEvalCtx &ctx, ObDat int ret = OB_SUCCESS; ObDatum *gis_datum1 = NULL; ObDatum *gis_datum2 = NULL; - ObDatum *gis_unit = NULL; ObExpr *gis_arg1 = expr.args_[0]; ObExpr *gis_arg2 = expr.args_[1]; - const int max_arg_num = 3; ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx); common::ObArenaAllocator &temp_allocator = tmp_alloc_g.get_allocator(); @@ -250,7 +248,9 @@ int ObExprSTDistance::eval_st_distance(const ObExpr &expr, ObEvalCtx &ctx, ObDat ObGeoExprUtils::geo_func_error_handle(ret, N_ST_DISTANCE); } } else { + const int max_arg_num = 3; if (expr.arg_cnt_ == max_arg_num) { + ObDatum *gis_unit = NULL; double factor = 0.0; if (OB_FAIL(expr.args_[max_arg_num - 1]->eval(ctx, gis_unit))) { LOG_WARN("eval geo unit arg failed", K(ret));