Fix possible segfault in schema inference for JSON formats

This commit is contained in:
avogar 2022-04-13 12:34:40 +00:00
parent 71dc0f0616
commit 348cae0d16
3 changed files with 15 additions and 0 deletions

View File

@ -255,6 +255,10 @@ struct JSONEachRowFieldsExtractor
std::vector<Element> extract(const Element & element)
{
/// {..., "<column_name>" : <value>, ...}
if (!element.isObject())
throw Exception(ErrorCodes::INCORRECT_DATA, "Root JSON value is not an object");
auto object = element.getObject();
std::vector<Element> fields;
fields.reserve(object.size());
@ -287,6 +291,9 @@ struct JSONCompactEachRowFieldsExtractor
std::vector<Element> extract(const Element & element)
{
/// [..., <value>, ...]
if (!element.isArray())
throw Exception(ErrorCodes::INCORRECT_DATA, "Root JSON value is not an array");
auto array = element.getArray();
std::vector<Element> fields;
fields.reserve(array.size());

View File

@ -0,0 +1,8 @@
-- Tags: no-backward-compatibility-check:22.4.1.1
insert into function file('02268_data.jsonl', 'TSV') select 1;
select * from file('02268_data.jsonl'); --{serverError CANNOT_EXTRACT_TABLE_STRUCTURE}
insert into function file('02268_data.jsonCompactEachRow', 'TSV') select 1;
select * from file('02268_data.jsonCompactEachRow'); --{serverError CANNOT_EXTRACT_TABLE_STRUCTURE}