Skip to content

Fix Any recursion depth for packed regular messages#27514

Open
XananasX7 wants to merge 1 commit into
protocolbuffers:mainfrom
XananasX7:fix-python-any-regular-recursion-depth
Open

Fix Any recursion depth for packed regular messages#27514
XananasX7 wants to merge 1 commit into
protocolbuffers:mainfrom
XananasX7:fix-python-any-regular-recursion-depth

Conversation

@XananasX7
Copy link
Copy Markdown

This updates Python ProtoJSON parsing so regular messages packed inside Any are routed through ConvertMessage() instead of directly through _ConvertFieldValuePair().

ConvertMessage() owns max_recursion_depth accounting. The existing nested-Any fix already uses it for well-known types, but the regular-message branch still bypassed one message-entry depth step. That
allowed alternating Any -> regular message -> Any -> regular message inputs to consume less recursion budget than equivalent nested messages.

The patch also restores the recursion-depth counter with finally, so failed parses do not leave stale parser state.

A regression test covers:

  • deeply nested Any values packing proto3.TestAny, which now fail at max_recursion_depth=5
  • a shallower packed regular-message chain that still parses successfully

Validation:

  • python3 -m py_compile python/google/protobuf/json_format.py python/google/protobuf/internal/json_format_test.py
  • git diff --check origin/main..HEAD
  • local dynamic-descriptor harness confirming 2 packed regular wrappers pass at depth 5 and 3 wrappers fail

@XananasX7 XananasX7 requested a review from a team as a code owner May 21, 2026 23:35
@XananasX7 XananasX7 requested review from ericsalo and removed request for a team May 21, 2026 23:35
@ericsalo ericsalo requested review from anandolee and removed request for ericsalo May 21, 2026 23:36
@rgoldfinger6 rgoldfinger6 added the 🅰️ safe for tests Mark a commit as safe to run presubmits over label May 22, 2026
@github-actions github-actions Bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants