wwbmmm opened a new pull request, #3499:
URL: https://github.com/apache/brpc/pull/3499

   ### What problem does this PR solve?
   
   Problem Summary:
   
   The mcpack2pb parser (used by nshead_mcpack / ubrpc / public_pbrpc
   requests) has no limit on the nesting depth of the input object/array.
   For a protobuf message that references itself (e.g. a `repeated`
   message field), the generated parser recurses once per nesting level,
   so an input nested deep enough makes the recursion grow unbounded and
   overflow the stack, crashing the process. The serializer has enforced
   MAX_DEPTH (`src/mcpack2pb/field_type.h`) since the beginning, the
   parser just never did.
   
   ### What is changed and the side effects?
   
   Changed:
   
   - Thread the current nesting depth through `mcpack2pb::UnparsedValue`
     and the `ObjectIterator` / `ArrayIterator` constructors.
   - Fail the parse (mark the input stream bad) as soon as the depth
     exceeds `MAX_DEPTH` (128), exactly like the serializer already does,
     so that the recursion stops at a bounded level instead of exhausting
     the stack.
   - Add unit tests covering both a deeply-nested payload (rejected
     without crashing) and a moderately-nested one (parsed normally).
   
   The depth limit is enforced on the iterator level, so existing code
   generated by `protoc-gen-mcpack` is protected without regeneration:
   no generated-code API is changed.
   
   Side effects:
   - Parsing now fails for mcpack input nested deeper than 128 levels
     (the same limit the serializer already applies). Such input is
     abnormal for any real workload, roughly matching
     `json2pb_max_recursion_depth` (100) used by the JSON parser.
   - Performance effects: none (one integer compare per iterator).
   
   - Breaking backward compatibility: no.
   
   ### Check List:
   - Please make sure your changes are compilable.
   - When providing us with a new feature, it is best to add related tests.
   - Please follow [Contributor Covenant Code of 
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).


-- 
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