This is an automated email from the ASF dual-hosted git repository.
gangwu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/master by this push:
new 0ba08a0 ORC-580:[C++] Verify ColumnEncodings in StripeFooter (#463)
0ba08a0 is described below
commit 0ba08a092dd5ee30a16f7d09c032f8cb2ccaf041
Author: Quanlong Huang <[email protected]>
AuthorDate: Fri Jan 3 10:33:49 2020 +0800
ORC-580:[C++] Verify ColumnEncodings in StripeFooter (#463)
ORC-580: [C++] Verify ColumnEncodings in StripeFooter
ColumnEncodings parsed from the StripeFooter could be corrupt. We should
verify it before using it to avoid crash.
This fixes #463
---
c++/src/Reader.cc | 7 +++++++
examples/corrupt/stripe_footer_bad_column_encodings.orc | Bin 0 -> 780 bytes
tools/test/TestFileScan.cc | 11 +++++++++++
3 files changed, 18 insertions(+)
diff --git a/c++/src/Reader.cc b/c++/src/Reader.cc
index 7957bda..ade2c29 100644
--- a/c++/src/Reader.cc
+++ b/c++/src/Reader.cc
@@ -395,6 +395,13 @@ namespace orc {
throw ParseError(std::string("bad StripeFooter from ") +
pbStream->getName());
}
+ // Verify StripeFooter in case it's corrupt
+ if (result.columns_size() != contents.footer->types_size()) {
+ std::stringstream msg;
+ msg << "bad number of ColumnEncodings in StripeFooter: expected="
+ << contents.footer->types_size() << ", actual=" <<
result.columns_size();
+ throw ParseError(msg.str());
+ }
return result;
}
diff --git a/examples/corrupt/stripe_footer_bad_column_encodings.orc
b/examples/corrupt/stripe_footer_bad_column_encodings.orc
new file mode 100644
index 0000000..2446623
Binary files /dev/null and
b/examples/corrupt/stripe_footer_bad_column_encodings.orc differ
diff --git a/tools/test/TestFileScan.cc b/tools/test/TestFileScan.cc
index c8b5fe8..b4938ea 100644
--- a/tools/test/TestFileScan.cc
+++ b/tools/test/TestFileScan.cc
@@ -135,3 +135,14 @@ TEST (TestFileScan, testBadCommand) {
EXPECT_EQ("", output);
EXPECT_EQ("The --batch parameter requires an integer option.\n", error);
}
+
+TEST (TestFileScan, testErrorHandling) {
+ const std::string pgm = findProgram("tools/src/orc-scan");
+ const std::string file =
findExample("corrupt/stripe_footer_bad_column_encodings.orc");
+ std::string output;
+ std::string error;
+ EXPECT_EQ(1, runProgram({pgm, file}, output, error));
+ EXPECT_EQ("", output);
+ EXPECT_NE(std::string::npos, error.find(
+ "bad number of ColumnEncodings in StripeFooter: expected=6, actual=0"));
+}