Repository navigation
fix: prevent stack overflow on circular key references during value expansion - #412
Closed
AdamMagued wants to merge 1 commit into
Closed
AdamMagued wants to merge 1 commit into
AdamMagued wants to merge 1 commit into
Conversation
…xpansion When expanding variable references (%(name)s), circular references between keys (such as a = %(b)s and b = %(a)s, or self-references in the default section) lead to infinite recursion during Key.String() evaluation, resulting in a fatal goroutine stack overflow panic. Track visited keys along the expansion path and enforce the recursion depth limit depthValues during recursive substitution. When a circular reference or unresolvable key is encountered, stop recursion cleanly and return the current string without crashing. Add regression tests covering mutual circular references, default section self-references, and multi-key cycles. Fixes go-ini#409
Author
|
Closing in favor of earlier community PR #410 to keep the review queue clean. |
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.
When resolving variable references (
%(name)s), circular references between keys (such asa = %(b)sandb = %(a)s, or self-references in the default section) result in infinite mutual recursive expansion duringKey.String()evaluation, causing a fatal goroutine stack overflow crash.Root Cause
Key.transformValuerecursively callednk.String()to resolve nested variable substitutions without tracking visited keys or bounding the recursion depth across calls. In the presence of a reference cycle, this led to unbounded recursive calls.Changes
*Keypointers along the expansion chain usinghasVisitedKeyandtransformValueWithVisited.depthValues(99) is encountered.key_test.gocovering two-key mutual circular references, default section self-references, and multi-key cycles.Fixes #409