Repository navigation
fix(proto): add recursion protection to physical plan and expression serde - #26741
Open
ninglinLiu wants to merge 1 commit into
Open
ninglinLiu wants to merge 1 commit into
ninglinLiu wants to merge 1 commit into
Conversation
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.
Which issue does this PR close?
Rationale for this change
Converting a physical plan or physical expression to and from protobuf recurses once per nesting level, but unlike logical plan serialization (#23823 / #24124) none of these functions had a
recursivestack-growth checkpoint. A deeply nested physical plan or expression could therefore abort the process with a native stack overflow, even whenrecursive_protectionis enabled.What changes are included in this PR?
Adds
#[cfg_attr(feature = "recursive_protection", recursive::recursive)]to the four recursive entry points of physical serde:PhysicalPlanNodeExt::try_from_physical_plan_with_converter(plan serialization)PhysicalPlanNodeExt::try_into_physical_plan_with_context(plan deserialization)serialize_physical_expr_with_converter(expression serialization)parse_physical_expr_with_converter(expression deserialization)Every child plan / child expression goes through these functions, including the default
PhysicalProtoConverterExtensionhooks, so this covers the whole recursion. Therecursivedependency andrecursive_protectionfeature already exist indatafusion-proto, so there are no Cargo changes.What is the testing strategy for this PR?
Added two tests to
datafusion/proto/tests/cases/stack_safety.rs(gated onrecursive_protection, like the existing growable-stack test) that round-trip, on a 2 MiB thread stack, a plan of 2,000 nestedGlobalLimitExecs and an expression of 2,000 nestedNotExprs. They reuse the existing child-process harness (generalised intorun_in_child_with) so a regression shows up as a test failure instead of aborting the test binary.Without the source change both new tests fail with
thread 'two-megabyte-stack' has overflowed its stack; with it they pass:cargo clippy -p datafusion-proto --all-targets --features recursive_protection -- -D warningsandcargo fmtare clean.Are there any user-facing changes?
No API changes. With
recursive_protectionenabled, deeply nested physical plans and expressions now serialize/deserialize instead of overflowing the stack.This PR was prepared with AI assistance and reviewed/tested by the author.