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));