Skip to content

THRIFT-6057: Limit struct read/write recursion depth in Rust library#3548

Draft
Jens-G wants to merge 1 commit into
apache:masterfrom
Jens-G:rust-recursion-depth
Draft

THRIFT-6057: Limit struct read/write recursion depth in Rust library#3548
Jens-G wants to merge 1 commit into
apache:masterfrom
Jens-G:rust-recursion-depth

Conversation

@Jens-G
Copy link
Copy Markdown
Member

@Jens-G Jens-G commented May 28, 2026

Summary

  • Introduces a thread-local DepthGuard RAII type in thrift::protocol that increments a per-thread counter on construction and decrements it via Drop
  • Generated read_from_in_protocol and write_to_out_protocol implementations (for both structs and unions) acquire a DepthGuard at entry
  • A depth ≥ 64 returns an immediate ProtocolError with kind = DepthLimit
  • Three unit tests cover: allow up to limit, reject at limit, restore depth on drop

Test plan

  • cargo test in lib/rs passes
  • Unit tests depth_guard_allows_up_to_limit, depth_guard_rejects_at_limit, depth_guard_restores_depth_on_drop pass
  • Cross-language tests unaffected

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

Client: rs

Introduces a thread-local DepthGuard RAII type in thrift::protocol that
increments a per-thread counter on construction and decrements it via Drop,
ensuring the counter is always restored even when the body returns an error.
Generated read_from_in_protocol and write_to_out_protocol implementations
(for both structs and unions) acquire a DepthGuard at entry; a depth >= 64
causes an immediate ProtocolError with kind DepthLimit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Jens-G Jens-G requested review from jimexist and mhlakhani as code owners May 28, 2026 11:40
@mergeable mergeable Bot added rust Pull requests that update Rust code compiler labels May 28, 2026
@Jens-G Jens-G marked this pull request as draft May 28, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant