From 6a2e00e877a097876463d62e25a63e1d7707e387 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 8 Jul 2020 15:23:15 +0200 Subject: [PATCH] ARROW-9373: [C++] Fix Parquet crash on invalid input (OSS-Fuzz) Should fix the following issue: * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=24005 Update testing submodule Update to ARROW-9373 --- cpp/src/parquet/schema.cc | 34 ++++++++++++++++++++++++++-------- testing | 2 +- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/cpp/src/parquet/schema.cc b/cpp/src/parquet/schema.cc index ac3f759e80a..b1be41f2169 100644 --- a/cpp/src/parquet/schema.cc +++ b/cpp/src/parquet/schema.cc @@ -35,6 +35,16 @@ namespace parquet { namespace schema { +namespace { + +void ThrowInvalidLogicalType(const LogicalType& logical_type) { + std::stringstream ss; + ss << "Invalid logical type: " << logical_type.ToString(); + throw ParquetException(ss.str()); +} + +} // namespace + // ---------------------------------------------------------------------- // ColumnPath @@ -206,8 +216,10 @@ PrimitiveNode::PrimitiveNode(const std::string& name, Repetition::type repetitio } // For forward compatibility, create an equivalent logical type logical_type_ = LogicalType::FromConvertedType(converted_type_, decimal_metadata_); - DCHECK(logical_type_ && !logical_type_->is_nested() && - logical_type_->is_compatible(converted_type_, decimal_metadata_)); + if (!(logical_type_ && !logical_type_->is_nested() && + logical_type_->is_compatible(converted_type_, decimal_metadata_))) { + ThrowInvalidLogicalType(*logical_type_); + } if (type == Type::FIXED_LEN_BYTE_ARRAY) { if (length <= 0) { @@ -249,8 +261,10 @@ PrimitiveNode::PrimitiveNode(const std::string& name, Repetition::type repetitio logical_type_ = NoLogicalType::Make(); converted_type_ = logical_type_->ToConvertedType(&decimal_metadata_); } - DCHECK(logical_type_ && !logical_type_->is_nested() && - logical_type_->is_compatible(converted_type_, decimal_metadata_)); + if (!(logical_type_ && !logical_type_->is_nested() && + logical_type_->is_compatible(converted_type_, decimal_metadata_))) { + ThrowInvalidLogicalType(*logical_type_); + } if (physical_type == Type::FIXED_LEN_BYTE_ARRAY) { if (physical_length <= 0) { @@ -296,8 +310,10 @@ GroupNode::GroupNode(const std::string& name, Repetition::type repetition, : Node(Node::GROUP, name, repetition, converted_type, id), fields_(fields) { // For forward compatibility, create an equivalent logical type logical_type_ = LogicalType::FromConvertedType(converted_type_); - DCHECK(logical_type_ && (logical_type_->is_nested() || logical_type_->is_none()) && - logical_type_->is_compatible(converted_type_)); + if (!(logical_type_ && (logical_type_->is_nested() || logical_type_->is_none()) && + logical_type_->is_compatible(converted_type_))) { + ThrowInvalidLogicalType(*logical_type_); + } field_name_to_idx_.clear(); auto field_idx = 0; @@ -327,8 +343,10 @@ GroupNode::GroupNode(const std::string& name, Repetition::type repetition, logical_type_ = NoLogicalType::Make(); converted_type_ = logical_type_->ToConvertedType(nullptr); } - DCHECK(logical_type_ && (logical_type_->is_nested() || logical_type_->is_none()) && - logical_type_->is_compatible(converted_type_)); + if (!(logical_type_ && (logical_type_->is_nested() || logical_type_->is_none()) && + logical_type_->is_compatible(converted_type_))) { + ThrowInvalidLogicalType(*logical_type_); + } field_name_to_idx_.clear(); auto field_idx = 0; diff --git a/testing b/testing index bd81ce53fe6..b6a2fc5fef8 160000 --- a/testing +++ b/testing @@ -1 +1 @@ -Subproject commit bd81ce53fe68daad0b591df15a38c6ce2458ceb4 +Subproject commit b6a2fc5fef8fe44cf815be4f7961a4fee5d08367