Add recursion depth limit to TProtocol.skip() in Python#3411
Merged
Conversation
Client: py C++ and Go already enforce a limit of 64 recursive skip() calls via TInputRecursionTracker and maxDepth respectively. This change adds an equivalent max_depth=64 parameter to the Python skip() implementation in TProtocolBase, raising TProtocolException(DEPTH_LIMIT) when the limit is exceeded. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
mhlakhani
approved these changes
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TProtocolBase.skip()in Python had no recursion depth limit. When deserializing an unknown field, generated code callsskip(), which recursively calls itself for each nested container or struct element. C++, Go, and Node.js all cap this recursion at 64 levels and raise a protocol exception when the limit is exceeded.This change brings Python into parity:
lib/py/src/protocol/TProtocol.py:skip()gains an optionalmax_depthparameter (default 64). At the start of each call, ifmax_depth <= 0aTProtocolException(DEPTH_LIMIT)is raised. All recursive calls passmax_depth - 1.Tests added in
lib/py/test/thrift_TBinaryProtocol.py:test_skip_rejects_deeply_nested_struct: a payload with 64 levels of nesting raisesDEPTH_LIMIT.test_skip_accepts_struct_within_depth_limit: a payload with 63 levels succeeds.Test plan
python3 lib/py/test/thrift_TBinaryProtocol.py -v— two new skip depth tests pass🤖 Generated with Claude Code