protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

[C++] Allow user specified recursion depth in json_util functions

Open JamesLee-Jones opened this issue 1 year ago • 4 comments

What language does this apply to? C++

Describe the problem you are trying to solve. Allow the recursion limit when writing JSONs to be increased.

Describe the solution you'd like An additional argument to each of the functions in json_uti.h/cc that allows a user specified recursion limit. This could be given the a default value to preserve backwards compatibility. For the MessageTo... and BinaryTo... functions set_max_recursion_depth could then be called on proto_source in BinaryToJsonStream. Something equivalent should be done to increase the parse limit.

Describe alternatives you've considered A compile time option that allows the default recursion depth specified by kDefaultMaxRecursionDepth in protostream_objectsource.cc to be increased.

JamesLee-Jones avatar Jun 24 '24 15:06 JamesLee-Jones

This seems like something we could accept a contribution for if introduced in a backwards compatible manner.

@haberman WDYT?

zhangskz avatar Jul 01 '24 21:07 zhangskz

This seems reasonable. I agree we could accept a contribution if it was done in a backwards-compatible manner.

By the way, protostream_objectsource.cc is not part of our repo anymore. It was removed in 2022: https://github.com/protocolbuffers/protobuf/commit/32bea52ee660abeb6a2891e3dce979a909cbd6ea

haberman avatar Jul 08 '24 23:07 haberman

This seems reasonable. I agree we could accept a contribution if it was done in a backwards-compatible manner.

By the way, protostream_objectsource.cc is not part of our repo anymore. It was removed in 2022: 32bea52

If the file protostream_objectsource.cc is no longer part of the repo, Is there an alternative other than compile time option or source code change, by increasing kDefaultMaxRecursionDepth, for protobuf users?

eslam-ahmed-khair avatar Aug 22 '24 13:08 eslam-ahmed-khair

Is there an alternative other than compile time option or source code change, by increasing kDefaultMaxRecursionDepth, for protobuf users?

No, that is what this issue is proposing to fix.

Currently the internal ParseOptions has a field recursion_depth that allows this to be configured at runtime: https://github.com/protocolbuffers/protobuf/blob/0ed61f0b15343d6450a55413748aa71a6ded0842/src/google/protobuf/json/internal/lexer.h#L48-L50

However the public ParseOptions struct does not have a field for this: https://github.com/protocolbuffers/protobuf/blob/0ed61f0b15343d6450a55413748aa71a6ded0842/src/google/protobuf/json/json.h#L26-L36

Probably all we need to do is add a field to the public ParseOptions struct and plumb it through to the internal one.

haberman avatar Aug 26 '24 18:08 haberman

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.

github-actions[bot] avatar Nov 25 '24 10:11 github-actions[bot]

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

github-actions[bot] avatar Dec 10 '24 10:12 github-actions[bot]