fix(hclsyntax): implement recursion depth limit inside parseBinaryOps to prevent stack overflow#812
Open
PARTH-AI-DS20 wants to merge 1 commit into
Open
fix(hclsyntax): implement recursion depth limit inside parseBinaryOps to prevent stack overflow#812PARTH-AI-DS20 wants to merge 1 commit into
PARTH-AI-DS20 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.
Summary
This PR introduces a hard recursion depth threshold of
1000loops insideparseBinaryOpsto safely intercept deeply nested expressions (such as thousands of sequential parenthetical configurations) before they exhaust the standard Go goroutine stack runtime allocation.Root Cause & Resolution
(((((...))))), the recursive descent structure ofparseBinaryOpscontinually allocates frames on the stack. This eventually results in a non-recoverable, fatal stack overflow panic (runtime: goroutine stack exceeds 1000000000-byte limit).recursionDepthto the internal packageparserstruct. EnteringparseBinaryOpsincrements this counter, checks against a strict max ceiling (1000), and returns a structuredhcl.Diagnosticpayload gracefully if crossed instead of throwing an unhandled panic. It clears down via a deferred frame decrement step.TestParseExpression_nestedParenthesesRecursionGuardinsideparser_test.goto assert defensive validation engine boundaries.Fixes #809