Skip to content

fix(proto): add recursion protection to logical plan deserialization - #26758

Open
Tim-53 wants to merge 1 commit into
apache:mainfrom
Tim-53:fix/proto-logical-plan-deserialize-recursion
Open

Tim-53 wants to merge 1 commit into
apache:mainfrom
Tim-53:fix/proto-logical-plan-deserialize-recursion

Conversation

@Tim-53

@Tim-53 Tim-53 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Deserializing a logical plan from protobuf recurses once per nesting level, through LogicalPlanNode::try_into_logical_plan. Serialization already has a recursive stack-growth checkpoint (#23823 / #24124), but deserialization did not. In debug builds, where this function has a very large stack frame, a deeply nested plan could abort the process with a native stack overflow, even with recursive_protection enabled.

What changes are included in this PR?

Adds #[cfg_attr(feature = "recursive_protection", recursive::recursive)] to try_into_logical_plan. Every plan-to-plan recursion goes through this function.

What is the testing strategy for this PR?

Adds deeply_nested_logical_plan_deserialization_uses_a_growable_stack to datafusion/proto/tests/cases/stack_safety.rs. It converts a plan with 2,000 nested SubqueryAlias nodes to proto and back on a 2 MiB thread stack.

Are there any user-facing changes?

No API changes. With recursive_protection enabled, deeply nested logical plans now deserialize instead of overflowing the stack.


This PR was prepared with AI assistance and reviewed by the author.

`LogicalPlanNode::try_into_logical_plan` recurses once per plan node
but, unlike serialization (apache#24124), had no `recursive` stack-growth
checkpoint, so a deeply nested plan could overflow the stack.

Add the `recursive_protection` checkpoint to `try_into_logical_plan`
and a stack safety test that round-trips a 2,000-deep plan on a 2 MiB
thread.

Closes apache#26737.
@github-actions github-actions Bot added the proto Related to proto crate label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proto Related to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proto: recursion protection for deserializing logical plans

1 participant