Merge pull request #37760 from Avogar/fix-segfault-template-format

Fix possible segfault in schema inference
This commit is contained in:
Kruglov Pavel 2022-06-02 13:01:47 +02:00 committed by GitHub
commit 9bb9df9928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 9 deletions

View File

@ -100,18 +100,21 @@ ColumnsDescription readSchemaFromFormat(
catch (...)
{
auto exception_message = getCurrentExceptionMessage(false);
size_t rows_read = schema_reader->getNumRowsRead();
assert(rows_read <= max_rows_to_read);
max_rows_to_read -= schema_reader->getNumRowsRead();
if (rows_read != 0 && max_rows_to_read == 0)
if (schema_reader)
{
exception_message += "\nTo increase the maximum number of rows to read for structure determination, use setting input_format_max_rows_to_read_for_schema_inference";
if (iterations > 1)
size_t rows_read = schema_reader->getNumRowsRead();
assert(rows_read <= max_rows_to_read);
max_rows_to_read -= schema_reader->getNumRowsRead();
if (rows_read != 0 && max_rows_to_read == 0)
{
exception_messages += "\n" + exception_message;
break;
exception_message += "\nTo increase the maximum number of rows to read for structure determination, use setting input_format_max_rows_to_read_for_schema_inference";
if (iterations > 1)
{
exception_messages += "\n" + exception_message;
break;
}
retry = false;
}
retry = false;
}
if (!retry || !isRetryableSchemaInferenceError(getCurrentExceptionCode()))

View File

@ -0,0 +1,2 @@
insert into function file(data_02318.tsv) select * from numbers(10);
desc file('data_02318.tsv', 'Template') SETTINGS format_template_row='nonexist', format_template_resultset='nonexist'; -- {serverError CANNOT_EXTRACT_TABLE_STRUCTURE}