Skip to content

Harden stack overflow protection #966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 18, 2025
Merged

Conversation

goto-bus-stop
Copy link
Member

This adds stack overflow protection to the existing "Variable Is Used" and "Fragment Is Used" validations, and the newly introduced subscription validation #963. Additionally, this significantly improves performance of the "Fragment Is Used" validation, which used to walk almost the entire document AST for each fragment definition, and now only does it once.

You need a lot of fragments to cause these to overflow, so it's only a problem for users who don't have a token limit configured or have it set much higher than the Router default.

@goto-bus-stop goto-bus-stop requested a review from a team as a code owner April 15, 2025 09:38
@@ -1089,6 +1089,60 @@ const DEFAULT_RECURSION_LIMIT: usize = 32;
#[non_exhaustive]
struct RecursionLimitError {}

/// Track recursion depth to prevent stack overflow.
#[derive(Debug)]
struct DepthCounter {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct really is just an integer with extra steps, but I wanted to mimick the pattern that we have with RecursionStack in the other recursion-limited functions.

@goto-bus-stop goto-bus-stop merged commit ebe09fe into main Apr 18, 2025
12 checks passed
@goto-bus-stop goto-bus-stop deleted the renee/overflow-protection branch April 18, 2025 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants