From 1cd888f505b42136e60177f19527d22b1566672e Mon Sep 17 00:00:00 2001 From: Andrei Nekrashevich Date: Mon, 1 Jun 2020 02:40:38 +0300 Subject: [PATCH] fix --- src/Functions/fuzzBits.cpp | 6 ++++++ tests/queries/0_stateless/01284_fuzz_bits.sql | 1 + 2 files changed, 7 insertions(+) diff --git a/src/Functions/fuzzBits.cpp b/src/Functions/fuzzBits.cpp index d2180c0bbba..8acee9c7bf0 100644 --- a/src/Functions/fuzzBits.cpp +++ b/src/Functions/fuzzBits.cpp @@ -20,6 +20,7 @@ namespace ErrorCodes extern const int ILLEGAL_TYPE_OF_ARGUMENT; extern const int ILLEGAL_COLUMN; extern const int DECIMAL_OVERFLOW; + extern const int ARGUMENT_OUT_OF_BOUND; } @@ -86,6 +87,11 @@ public: auto col_in_untyped = block.getByPosition(arguments[0]).column; const double inverse_probability = assert_cast(*block.getByPosition(arguments[1]).column).getValue(); + if (inverse_probability < 0.0 || 1.0 < inverse_probability) + { + throw Exception("Second argument of function " + getName() + " must be from `0.0` to `1.0`", ErrorCodes::ARGUMENT_OUT_OF_BOUND); + } + if (const ColumnConst * col_in_untyped_const = checkAndGetColumnConstStringOrFixedString(col_in_untyped.get())) { col_in_untyped = col_in_untyped_const->getDataColumnPtr(); diff --git a/tests/queries/0_stateless/01284_fuzz_bits.sql b/tests/queries/0_stateless/01284_fuzz_bits.sql index 48e6578fcb1..24da23787cb 100644 --- a/tests/queries/0_stateless/01284_fuzz_bits.sql +++ b/tests/queries/0_stateless/01284_fuzz_bits.sql @@ -1,4 +1,5 @@ SELECT fuzzBits(toString('string'), 1); -- { serverError 43 } +SELECT fuzzBits('string', -1.0); -- { serverError 69 } SELECT fuzzBits('', 0.3); SELECT length(fuzzBits(randomString(100), 0.5)); SELECT toTypeName(fuzzBits(randomString(100), 0.5));