From 62c5951dd7888e029e442d756200867d04745de3 Mon Sep 17 00:00:00 2001 From: avogar Date: Tue, 2 Nov 2021 16:26:14 +0300 Subject: [PATCH] Fix segfault in formatRow function --- src/Functions/formatRow.cpp | 7 +++++++ tests/queries/0_stateless/02113_format_row_bug.reference | 0 tests/queries/0_stateless/02113_format_row_bug.sql | 5 +++++ 3 files changed, 12 insertions(+) create mode 100644 tests/queries/0_stateless/02113_format_row_bug.reference create mode 100644 tests/queries/0_stateless/02113_format_row_bug.sql diff --git a/src/Functions/formatRow.cpp b/src/Functions/formatRow.cpp index ee9696cf34f..3f9d3e782d7 100644 --- a/src/Functions/formatRow.cpp +++ b/src/Functions/formatRow.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -18,6 +19,7 @@ namespace ErrorCodes extern const int ILLEGAL_TYPE_OF_ARGUMENT; extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; extern const int UNKNOWN_FORMAT; + extern const int BAD_ARGUMENTS; } namespace @@ -70,6 +72,11 @@ public: writeChar('\0', buffer); offsets[row] = buffer.count(); }); + + /// This function make sense only for row output formats. + if (!dynamic_cast(out.get())) + throw Exception(ErrorCodes::BAD_ARGUMENTS, "Cannot turn rows into a {} format strings. {} function supports only row output formats", format_name, getName()); + out->write(arg_columns); return col_str; } diff --git a/tests/queries/0_stateless/02113_format_row_bug.reference b/tests/queries/0_stateless/02113_format_row_bug.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/02113_format_row_bug.sql b/tests/queries/0_stateless/02113_format_row_bug.sql new file mode 100644 index 00000000000..971a2bee2b0 --- /dev/null +++ b/tests/queries/0_stateless/02113_format_row_bug.sql @@ -0,0 +1,5 @@ +select formatRow('ORC', number, toDate(number)) from numbers(5); -- { serverError 36 } +select formatRow('Parquet', number, toDate(number)) from numbers(5); -- { serverError 36 } +select formatRow('Arrow', number, toDate(number)) from numbers(5); -- { serverError 36 } +select formatRow('Native', number, toDate(number)) from numbers(5); -- { serverError 36 } +