You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by do...@apache.org on 2022/01/27 18:32:47 UTC
[orc] branch main updated: ORC-1101: [C++] Improve malformed STRUCT handling (#1023)
This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/main by this push:
new 54c235b ORC-1101: [C++] Improve malformed STRUCT handling (#1023)
54c235b is described below
commit 54c235b070a03cc79d17578a8131cddf2af56aac
Author: Heena Bansal <He...@ibm.com>
AuthorDate: Thu Jan 27 13:32:42 2022 -0500
ORC-1101: [C++] Improve malformed STRUCT handling (#1023)
### What changes were proposed in this pull request?
The changes are made to validate the indices in the Protobuf message type tree especially for the Type_Kind_STRUCT when fieldnames are less than the subtypes_size() , so it won't crash when we convert the proto::Types to TypeImpls.
### Why are the changes needed?
To handle the malformed STRUCT type more gracefully.
### How was this patch tested?
Pass the CIs with the newly added test coverage.
Closes #1021 and #1023
---
c++/src/TypeImpl.cc | 2 ++
c++/test/TestType.cc | 14 ++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/c++/src/TypeImpl.cc b/c++/src/TypeImpl.cc
index d65b084..14517ce 100644
--- a/c++/src/TypeImpl.cc
+++ b/c++/src/TypeImpl.cc
@@ -465,6 +465,8 @@ namespace orc {
case proto::Type_Kind_STRUCT: {
TypeImpl* result = new TypeImpl(STRUCT);
ret = std::unique_ptr<Type>(result);
+ if (type.subtypes_size() > type.fieldnames_size())
+ throw ParseError("Illegal STRUCT type that contains less fieldnames than subtypes");
for(int i=0; i < type.subtypes_size(); ++i) {
result->addStructField(type.fieldnames(i),
convertType(footer.types(static_cast<int>
diff --git a/c++/test/TestType.cc b/c++/test/TestType.cc
index 1473462..7d30f60 100644
--- a/c++/test/TestType.cc
+++ b/c++/test/TestType.cc
@@ -404,6 +404,20 @@ namespace orc {
illUnionType.set_kind(proto::Type_Kind_UNION);
testCorruptHelper(illUnionType, footer,
"Illegal UNION type that doesn't contain any subtypes");
+
+ proto::Type illStructType;
+ proto::Type structType;
+ illStructType.set_kind(proto::Type_Kind_STRUCT);
+ structType.set_kind(proto::Type_Kind_STRUCT);
+ structType.add_subtypes(0); // construct a loop back to root
+ structType.add_fieldnames("root");
+ illStructType.add_subtypes(1);
+ illStructType.add_fieldnames("f1");
+ illStructType.add_subtypes(2);
+ *(footer.add_types()) = illStructType;
+ *(footer.add_types()) = structType;
+ testCorruptHelper(illStructType, footer,
+ "Illegal STRUCT type that contains less fieldnames than subtypes");
}
void expectParseError(const proto::Footer &footer, const char* errMsg) {