THRIFT-6048: Limit struct read/write recursion depth in Perl library#3553
Open
Jens-G wants to merge 1 commit into
Open
THRIFT-6048: Limit struct read/write recursion depth in Perl library#3553Jens-G wants to merge 1 commit into
Jens-G wants to merge 1 commit into
Conversation
f530997 to
8f10fa5
Compare
Client: perl The Perl generator wraps each generated read()/write() body with incrementRecursionDepth()/eval/decrementRecursionDepth() on Thrift::Protocol (limit DEFAULT_RECURSION_DEPTH = 64, Thrift::TProtocolException::DEPTH_LIMIT on excess). Previously only skip() was bounded, so the generated read/write path recursed without limit. Unions and exceptions are generated through the same path, so they are bounded too. Replace the isolated counter test with a generated-code round-trip (lib/perl/t/recursion_depth.t) over a recursive struct (RecTree), union (RecUnion) and exception (RecError) from a new RecursionDepth.thrift, driven through the generated read()/write() on a real BinaryProtocol: a chain at the limit round-trips (also proving the guards do not double-count), a chain past it is rejected on write, and a hand-serialized over-limit payload is rejected on read (crafted with the real recursive field, id 1 = list<self>, so the reader recurses through the guarded path rather than the separate, unbounded skip()). Each rejection asserts the DEPTH_LIMIT code, not just any exception. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
8f10fa5 to
edc51fc
Compare
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.
THRIFT-6048: Limit struct read/write recursion depth in the Perl library
Change
The Perl generator wraps each generated
read()/write()body withincrementRecursionDepth()/eval/decrementRecursionDepth()onThrift::Protocol(limitDEFAULT_RECURSION_DEPTH= 64,Thrift::TProtocolException::DEPTH_LIMITon excess). Previously onlyskip()was bounded. Unions and exceptions are generated through the same path, so they are bounded too.Test
Replaces the isolated counter test with a generated-code round-trip (
lib/perl/t/recursion_depth.t) over a recursive struct (RecTree), union (RecUnion) and exception (RecError) from a newRecursionDepth.thrift, on a realBinaryProtocol. For each of the three kinds:list<self>) so the reader recurses through the guarded path rather than the separate, unboundedskip().Each rejection asserts the
DEPTH_LIMITcode specifically, not merely that an exception was thrown. Validated locally with Perl 5.34 (Test::More+Test::Exception): 21/21 ok. Perl is binary-only (no Compact/JSON modules). No functional Perl CI (--without-perl); SCA runs perlcritic, which excludest/.🤖 Generated with Claude Code