Copilot commented on code in PR #3099:
URL: https://github.com/apache/brpc/pull/3099#discussion_r2365558102


##########
src/json2pb/pb_to_json.cpp:
##########
@@ -52,22 +104,26 @@ class PbToJsonConverter {
     explicit PbToJsonConverter(const Pb2JsonOptions& opt) : _option(opt) {}
 
     template <typename Handler>
-    bool Convert(const google::protobuf::Message& message, Handler& handler, 
bool root_msg = false);
+    bool Convert(const google::protobuf::Message& message, Handler& handler, 
bool root_msg = false, int depth = 0);
 
     const std::string& ErrorText() const { return _error; }
 
 private:
     template <typename Handler>
     bool _PbFieldToJson(const google::protobuf::Message& message,
                         const google::protobuf::FieldDescriptor* field,
-                        Handler& handler);
+                        Handler& handler, int depth);
 
     std::string _error;
     Pb2JsonOptions _option;
 };
 
 template <typename Handler>
-bool PbToJsonConverter::Convert(const google::protobuf::Message& message, 
Handler& handler, bool root_msg) {
+bool PbToJsonConverter::Convert(const google::protobuf::Message& message, 
Handler& handler, bool root_msg, int depth) {
+    if (depth > FLAGS_json2pb_max_recursion_depth) {

Review Comment:
   The depth check should use '>=' to be consistent with the ExceedMaxDepth 
function which uses '>=' at line 42.
   ```suggestion
       if (depth >= FLAGS_json2pb_max_recursion_depth) {
   ```



##########
src/json2pb/json_to_pb.cpp:
##########
@@ -526,7 +536,12 @@ bool JsonValueToProtoMessage(const 
BUTIL_RAPIDJSON_NAMESPACE::Value& json_value,
                              google::protobuf::Message* message,
                              const Json2PbOptions& options,
                              std::string* err,
+                             int depth,
                              bool root_val) {
+    if (depth > FLAGS_json2pb_max_recursion_depth) {

Review Comment:
   The depth check should use '>=' to be consistent with the pb_to_json.cpp 
implementation and to ensure the limit is enforced at exactly the configured 
depth.
   ```suggestion
       if (depth >= FLAGS_json2pb_max_recursion_depth) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to