THRIFT-6047: Limit struct/union/exception read/write recursion depth in PHP library#3552
Open
Jens-G wants to merge 1 commit into
Open
THRIFT-6047: Limit struct/union/exception read/write recursion depth in PHP library#3552Jens-G wants to merge 1 commit into
Jens-G wants to merge 1 commit into
Conversation
sveneld
reviewed
May 28, 2026
Contributor
sveneld
left a comment
There was a problem hiding this comment.
Functionally solid — see two style nits inline. Will follow up on the binary_inline / integration-test items separately.
b8b00bc to
a89e821
Compare
a89e821 to
be3d387
Compare
sveneld
reviewed
May 31, 2026
…in PHP library Client: php A recursion-depth counter (incrementRecursionDepth/decrementRecursionDepth, limit DEFAULT_RECURSION_DEPTH = 64, TProtocolException::DEPTH_LIMIT on excess) is enforced at the two mutually exclusive generated-code call sites: the generator wraps the inline read/write loop (default --gen php), and TBase::readStruct/writeStruct carry the guard for oop mode. Previously only skip() was bounded. Also guard TException::readStruct/writeStruct. TException does not extend TBase -- it carries its own copy of those methods -- so oop-mode exceptions (generated read()/write() delegate to them) were still unbounded after the TBase change. They now increment/try/finally/decrement identically, so a recursive exception is bounded in both inline and oop modes. Replace the isolated unit tests with a generated-code round-trip integration test over a recursive struct (RecTree), union (RecUnion) and exception (RecError) from RecursionDepth.thrift, generated in both modes (PhpRec inline, PhpRecOop oop) and exercised over Binary, Compact and JSON: a chain at exactly the limit round-trips (proving the inline and oop 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 struct path rather than skip()). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
be3d387 to
ac82ebe
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-6047: Limit struct/union/exception read/write recursion depth in the PHP library
Change
Enforces a recursion-depth counter (
incrementRecursionDepth/decrementRecursionDepthonTProtocol, limitDEFAULT_RECURSION_DEPTH= 64,TProtocolException::DEPTH_LIMITon excess) at the two mutually exclusive generated-code call sites: the generator wraps the inline read/write loop (default--gen php), andTBase::readStruct/writeStructcarry the guard for oop mode. Previously onlyskip()was bounded.Also guards
TException::readStruct/writeStruct.TExceptiondoes not extendTBase— it carries its own copies of those methods — so oop-mode exceptions (whose generatedread()/write()delegate to them) remained unbounded after theTBasechange. They now increment /try/finally/ decrement identically, closing the gap. (Found while adding the exception test below.)Test
A generated-code round-trip integration test over a recursive struct (
RecTree), union (RecUnion) and exception (RecError) fromRecursionDepth.thrift, generated in both modes (PhpRecinline,PhpRecOopoop) and exercised over Binary, Compact and JSON:list<self>) so the reader recurses through the guarded struct path rather than the separate, unboundedskip().Validated locally (PHP 8.1, PHPUnit 10.5): 54/54 pass;
phpcs(PSR-12) andphpstanclean. Without theTExceptionguard, the oop-mode exception write/read cases fail (the gap is real).binary_inlinemode (noTProtocol) stays unguarded as before.🤖 Generated with Claude Code