Skip to content

THRIFT-6051: Limit struct read/write recursion depth in OCaml library#3556

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

THRIFT-6051: Limit struct read/write recursion depth in OCaml library#3556
Jens-G wants to merge 1 commit into
apache:masterfrom
Jens-G:ocaml-recursion-depth

Conversation

@Jens-G
Copy link
Copy Markdown
Member

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

Summary

  • Adds recursion_depth_ field and increment_recursion_depth / decrement_recursion_depth methods to Protocol.t in Thrift.ml
  • Also fixes a pre-existing forward-reference bug: moves exn_type and exception E before class virtual t
  • OCaml generator wraps struct read/write with Fun.protect to guarantee decrement even on exception
  • Limit is 64; raises Protocol.E(DEPTH_LIMIT, …) on excess

Test plan

  • OCaml tests build and pass via dune test

🤖 Generated with Claude Code

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

Client: ocaml

- Add recursion_depth_ field and increment/decrement_recursion_depth
  methods to Protocol.t in Thrift.ml
- Move type exn_type and exception E before class virtual t to fix a
  pre-existing forward-reference bug (Protocol.INVALID_DATA in skip)
- Generator wraps struct read/write with Fun.protect to ensure
  decrement_recursion_depth always runs even on exception
- Limit is 64 levels; raises Protocol.E(DEPTH_LIMIT,...) on excess

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Jens-G Jens-G requested review from fishy and mhlakhani as code owners May 28, 2026 11:46
@Jens-G Jens-G marked this pull request as draft May 28, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant