Skip to content

Commit

Permalink
ORC-414: [C++] Check root type existence before reading files
Browse files Browse the repository at this point in the history
Fixes #438

Signed-off-by: Owen O'Malley <omalley@apache.org>
  • Loading branch information
stiga-huang authored and omalley committed Oct 22, 2019
1 parent f789ca2 commit 0635bb3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions c++/src/Reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,9 @@ namespace orc {
void checkProtoTypeIds(const proto::Footer &footer) {
std::stringstream msg;
int maxId = footer.types_size();
if (maxId <= 0) {
throw ParseError("Footer is corrupt: no types found");
}
for (int i = 0; i < maxId; ++i) {
const proto::Type& type = footer.types(i);
for (int j = 0; j < type.subtypes_size(); ++j) {
Expand Down
2 changes: 2 additions & 0 deletions c++/test/TestType.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ namespace orc {
TEST(TestType, testCheckProtoTypeIds) {
proto::Footer footer;
proto::Type rootType;
expectParseError(footer, "Footer is corrupt: no types found");

rootType.set_kind(proto::Type_Kind_STRUCT);
rootType.add_subtypes(1); // add a non existent type id
*(footer.add_types()) = rootType;
Expand Down

0 comments on commit 0635bb3

Please sign in to comment.