Skip to content

Commit

Permalink
[protobuf] Readded msg_size and field name check to ProcProtoMsg recu…
Browse files Browse the repository at this point in the history
…rsion (#1734) (#1735)

* Added msg_size and string find check to ProcProtoMsg recursion.

* Added same logic to dyn_proto sample

Co-authored-by: Peguen <[email protected]>
  • Loading branch information
eclipse-ecal-bot and Peguen authored Oct 2, 2024
1 parent 9e989cb commit 054c30b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions contrib/ecalproto/src/ecal_proto_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ namespace protobuf
std::vector<const google::protobuf::FieldDescriptor*> msg_fields;
msg.GetReflection()->ListFields(msg, &msg_fields);

ProcProtoMsg(msg, name.str(), complete_message_name, true, fnum);
if (prefix_.find(field->name()) == std::string::npos || !msg_fields.empty())
ProcProtoMsg(msg, name.str(), complete_message_name, true, fnum);
}
}
}
Expand All @@ -282,8 +283,9 @@ namespace protobuf
// do not process default messages to avoid infinite recursions.
std::vector<const google::protobuf::FieldDescriptor*> msg_fields;
msg.GetReflection()->ListFields(msg, &msg_fields);

ProcProtoMsg(msg, field->name(), complete_message_name, false, field->number());

if (prefix_.find(field->name()) == std::string::npos || !msg_fields.empty())
ProcProtoMsg(msg, field->name(), complete_message_name, false, field->number());
}
}
break;
Expand Down
6 changes: 4 additions & 2 deletions samples/cpp/pubsub/protobuf/proto_dyn/src/proto_dyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ void ProcProtoMsg(const google::protobuf::Message& msg_, const std::string& pref
std::vector<const google::protobuf::FieldDescriptor*> msg_fields;
msg.GetReflection()->ListFields(msg, &msg_fields);

ProcProtoMsg(msg, prefix);
if (prefix_.find(field->name()) == std::string::npos || !msg_fields.empty())
ProcProtoMsg(msg, prefix);
}
}
else
Expand All @@ -257,7 +258,8 @@ void ProcProtoMsg(const google::protobuf::Message& msg_, const std::string& pref
std::vector<const google::protobuf::FieldDescriptor*> msg_fields;
msg.GetReflection()->ListFields(msg, &msg_fields);

ProcProtoMsg(msg, prefix);
if (prefix_.find(field->name()) == std::string::npos || !msg_fields.empty())
ProcProtoMsg(msg, prefix);
}
}
break;
Expand Down

0 comments on commit 054c30b

Please sign in to comment.