Avoid abort in protobuf library in debug build

This commit is contained in:
avogar 2023-04-03 16:25:22 +00:00
parent fbb22348ea
commit 2cde63a25c
3 changed files with 45 additions and 5 deletions

View File

@ -41,8 +41,19 @@ public:
return descriptor;
const auto * file_descriptor = importer.Import(schema_path);
// If there are parsing errors, AddError() throws an exception and in this case the following line
// isn't executed.
if (error)
{
auto info = error.value();
error.reset();
throw Exception(
ErrorCodes::CANNOT_PARSE_PROTOBUF_SCHEMA,
"Cannot parse '{}' file, found an error at line {}, column {}, {}",
info.filename,
std::to_string(info.line),
std::to_string(info.column),
info.message);
}
assert(file_descriptor);
if (with_envelope == WithEnvelope::No)
@ -74,14 +85,24 @@ private:
// Overrides google::protobuf::compiler::MultiFileErrorCollector:
void AddError(const String & filename, int line, int column, const String & message) override
{
throw Exception(ErrorCodes::CANNOT_PARSE_PROTOBUF_SCHEMA,
"Cannot parse '{}' file, found an error at line {}, column {}, {}",
filename, std::to_string(line), std::to_string(column), message);
/// Protobuf library code is not exception safe, we should
/// remember error and throw in later from our side.
error = ErrorInfo{filename, line, column, message};
}
google::protobuf::compiler::DiskSourceTree disk_source_tree;
google::protobuf::compiler::Importer importer;
const WithEnvelope with_envelope;
struct ErrorInfo
{
String filename;
int line;
int column;
String message;
};
std::optional<ErrorInfo> error;
};

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Tags: no-fasttest
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
echo 'syntax = "proto3";
message Message {
NotExisted x = 1;
}' > 02705_schema.proto
$CLICKHOUSE_LOCAL -q "select * from file(data.bin, Protobuf) settings format_schema='schema:Message'" 2>&1 | grep -c "CANNOT_PARSE_PROTOBUF_SCHEMA"
rm 02705_schema.proto