From 0635bb34332e2abaed1fbe3673b35506463453b5 Mon Sep 17 00:00:00 2001 From: stiga-huang Date: Sat, 19 Oct 2019 21:51:10 +0800 Subject: [PATCH] ORC-414: [C++] Check root type existence before reading files Fixes #438 Signed-off-by: Owen O'Malley --- c++/src/Reader.cc | 3 +++ c++/test/TestType.cc | 2 ++ 2 files changed, 5 insertions(+) diff --git a/c++/src/Reader.cc b/c++/src/Reader.cc index ad87c15bbb..ef39a580d5 100644 --- a/c++/src/Reader.cc +++ b/c++/src/Reader.cc @@ -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) { diff --git a/c++/test/TestType.cc b/c++/test/TestType.cc index 4abfaf12f9..5d61f6f3ce 100644 --- a/c++/test/TestType.cc +++ b/c++/test/TestType.cc @@ -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;