parsers/c-based: add nesting depth limit to prevent stack overflow#4440
Open
pengfeixx wants to merge 1 commit into
Open
parsers/c-based: add nesting depth limit to prevent stack overflow#4440pengfeixx wants to merge 1 commit into
pengfeixx wants to merge 1 commit into
Conversation
Limit the maximum nesting depth in createTags() to MAX_NEST_LEVEL (1024) to prevent stack overflow when processing deeply nested braces (e.g. crafted Java source files with thousands of nested blocks). When the limit is exceeded, the parser skips to the matching brace instead of recursing, preventing unbounded stack growth that leads to SIGSEGV. Fixes: universal-ctags#4439
Member
|
Thank you. I'm thinking about fixing the original issue via #4387. |
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
MAX_NEST_LEVEL = 1024) to the C-based parser to prevent stack overflow when processing deeply nested bracesskipToMatch("{}")) instead of recursingChanges
parsers/c-based.c#define MAX_NEST_LEVEL 1024; added depth check increateTags()before recursivenest()callRoot Cause
The
createTags()→nest()→createTags()recursive call chain has no depth bound. When processing a file with deeply nested braces (e.g. 54000 levels), this causes uncontrolled stack growth leading to SIGSEGV.Test Plan
poc-java-stack-overflow-54000.java) attached to the issue — should no longer crashgcc -std=c99 -fsyntax-only— no compilation errorsFixes #4439