From b6761d31f30303e13d2f37f80c18024c1668be15 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 31 Jan 2020 23:16:46 +0300 Subject: [PATCH] Added range check to function h3EdgeLengthM --- dbms/src/Functions/h3EdgeLengthM.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/dbms/src/Functions/h3EdgeLengthM.cpp b/dbms/src/Functions/h3EdgeLengthM.cpp index 37293426b45..d3c0db4b4b5 100644 --- a/dbms/src/Functions/h3EdgeLengthM.cpp +++ b/dbms/src/Functions/h3EdgeLengthM.cpp @@ -4,14 +4,22 @@ # include # include # include +# include # include # include # include +# include namespace DB { + +namespace ErrorCodes +{ + extern const int ARGUMENT_OUT_OF_BOUND; +} + // Average metric edge length of H3 hexagon. The edge length `e` for given resolution `res` can // be used for converting metric search radius `radius` to hexagon search ring size `k` that is // used by `H3kRing` function. For small enough search area simple flat approximation can be used, @@ -50,7 +58,10 @@ public: for (const auto row : ext::range(0, input_rows_count)) { - const int resolution = col_hindex->getUInt(row); + const UInt64 resolution = col_hindex->getUInt(row); + if (resolution > MAX_H3_RES) + throw Exception("The argument 'resolution' (" + toString(resolution) + ") of function " + getName() + + " is out of bounds because the maximum resolution in H3 library is " + toString(MAX_H3_RES), ErrorCodes::ARGUMENT_OUT_OF_BOUND); Float64 res = edgeLengthM(resolution);