diff --git a/dbms/src/Functions/FunctionsCoding.h b/dbms/src/Functions/FunctionsCoding.h index 8734bbc03ed..872af899fae 100644 --- a/dbms/src/Functions/FunctionsCoding.h +++ b/dbms/src/Functions/FunctionsCoding.h @@ -1548,13 +1548,15 @@ public: ColumnString::Chars & vec_res_upper_range = col_res_upper_range->getChars(); vec_res_upper_range.resize(input_rows_count * IPV6_BINARY_LENGTH); + const UInt8 max_cidr_mask = IPV6_BINARY_LENGTH * 8; + for (size_t offset = 0; offset < input_rows_count; ++offset) { const size_t offset_ipv6 = offset * IPV6_BINARY_LENGTH; UInt8 cidr = col_const_cidr_in ? col_const_cidr_in->getValue() : col_cidr_in->getData()[offset]; - + cidr = std::min(cidr, max_cidr_mask); applyCIDRMask(&vec_in[offset_ipv6], &vec_res_lower_range[offset_ipv6], &vec_res_upper_range[offset_ipv6], cidr); } diff --git a/dbms/tests/queries/0_stateless/00938_ipv6_cidr_range.reference b/dbms/tests/queries/0_stateless/00938_ipv6_cidr_range.reference index 496b48a70ac..fe2a43fbda5 100644 --- a/dbms/tests/queries/0_stateless/00938_ipv6_cidr_range.reference +++ b/dbms/tests/queries/0_stateless/00938_ipv6_cidr_range.reference @@ -15,3 +15,4 @@ ffff:: 4 ('f000::','ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff') ('ffff:ffff:ffff:ffff::','ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff') ('::','ff:ffff:ffff:ffff:ffff:ffff:ffff:ffff') ('f000::','ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff') +1 diff --git a/dbms/tests/queries/0_stateless/00938_ipv6_cidr_range.sql b/dbms/tests/queries/0_stateless/00938_ipv6_cidr_range.sql index 624b996200f..5f69710b220 100644 --- a/dbms/tests/queries/0_stateless/00938_ipv6_cidr_range.sql +++ b/dbms/tests/queries/0_stateless/00938_ipv6_cidr_range.sql @@ -22,3 +22,4 @@ SELECT IPv6CIDRToRange(IPv6StringToNum('2001:0db8:0000:85a3:0000:0000:ac1f:8001' SELECT IPv6CIDRToRange(IPv6StringToNum('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'), 64); SELECT IPv6CIDRToRange(IPv6StringToNum('0000:0000:0000:0000:0000:0000:0000:0000'), 8); SELECT IPv6CIDRToRange(IPv6StringToNum('ffff:0000:0000:0000:0000:0000:0000:0000'), 4); +SELECT IPv6CIDRToRange(IPv6StringToNum('2001:0db8:0000:85a3:0000:0000:ac1f:8001'), 128) = IPv6CIDRToRange(IPv6StringToNum('2001:0db8:0000:85a3:0000:0000:ac1f:8001'), 200) ;