diff --git a/mediapipe/framework/tool/BUILD b/mediapipe/framework/tool/BUILD index b7c563b9..cc586a2c 100644 --- a/mediapipe/framework/tool/BUILD +++ b/mediapipe/framework/tool/BUILD @@ -501,7 +501,6 @@ cc_library( ":calculator_graph_template_cc_proto", ":proto_util_lite", "//mediapipe/framework:calculator_cc_proto", - "//mediapipe/framework/port:logging", "//mediapipe/framework/port:numbers", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", diff --git a/mediapipe/framework/tool/template_expander.cc b/mediapipe/framework/tool/template_expander.cc index a91ea5ad..a9af5c45 100644 --- a/mediapipe/framework/tool/template_expander.cc +++ b/mediapipe/framework/tool/template_expander.cc @@ -15,20 +15,14 @@ #include "mediapipe/framework/tool/template_expander.h" #include -#include #include #include -#include #include #include "absl/strings/ascii.h" #include "absl/strings/match.h" #include "absl/strings/numbers.h" -#include "absl/strings/str_join.h" -#include "absl/strings/str_split.h" #include "mediapipe/framework/calculator.pb.h" -#include "mediapipe/framework/port/canonical_errors.h" -#include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/port/numbers.h" #include "mediapipe/framework/port/ret_check.h" #include "mediapipe/framework/port/status.h" @@ -183,8 +177,7 @@ FieldType GetFieldType(const TemplateExpression& rule) { int FieldCount(const FieldValue& base, ProtoPath field_path, FieldType field_type) { int result = 0; - CHECK( - ProtoUtilLite::GetFieldCount(base, field_path, field_type, &result).ok()); + CHECK_OK(ProtoUtilLite::GetFieldCount(base, field_path, field_type, &result)); return result; } diff --git a/mediapipe/framework/tool/template_parser.cc b/mediapipe/framework/tool/template_parser.cc index 743df9fb..209def6a 100644 --- a/mediapipe/framework/tool/template_parser.cc +++ b/mediapipe/framework/tool/template_parser.cc @@ -471,7 +471,7 @@ class TemplateParser::Parser::ParserImpl { "\" stored in google.protobuf.Any."); return false; } - DO(ConsumeAnyValue(value_descriptor, &serialized_value)); + DO(ConsumeAnyValue(any_value_field, value_descriptor, &serialized_value)); if (singular_overwrite_policy_ == FORBID_SINGULAR_OVERWRITES) { // Fail if any_type_url_field has already been specified. if ((!any_type_url_field->is_repeated() && @@ -709,7 +709,7 @@ class TemplateParser::Parser::ParserImpl { // If the parse information tree is not NULL, create a nested one // for the nested message. ParseInfoTree* parent = parse_info_tree_; - if (parent != NULL) { + if (parent) { parse_info_tree_ = parent->CreateNested(field); } @@ -1191,8 +1191,20 @@ class TemplateParser::Parser::ParserImpl { // A helper function for reconstructing Any::value. Consumes a text of // full_type_name, then serializes it into serialized_value. - bool ConsumeAnyValue(const Descriptor* value_descriptor, + bool ConsumeAnyValue(const FieldDescriptor* field, + const Descriptor* value_descriptor, std::string* serialized_value) { + if (--recursion_limit_ < 0) { + ReportError("Message is too deep"); + return false; + } + // If the parse information tree is not NULL, create a nested one + // for the nested message. + ParseInfoTree* parent = parse_info_tree_; + if (parent) { + parse_info_tree_ = parent->CreateNested(field); + } + DynamicMessageFactory factory; const Message* value_prototype = factory.GetPrototype(value_descriptor); if (value_prototype == NULL) { @@ -1214,6 +1226,11 @@ class TemplateParser::Parser::ParserImpl { } value->AppendToString(serialized_value); } + + ++recursion_limit_; + + // Reset the parse information tree. + parse_info_tree_ = parent; return true; }