Java parser stack overflow / SIGSEGV on deeply nested braces
Summary
I found a reproducible crash in the Java parser of Universal Ctags when processing a Java source file with deeply nested braces.
This appears to be a stack exhaustion / uncontrolled recursion issue in the Java parser. It is similar in class to #4369, but it affects a different parser and call path.
Affected versions tested
I confirmed the crash on both current master and the latest release:
origin/master:
commit: cb432c71017551e66e4be9261019941b02227206
result: SIGSEGV in a plain build, exit code 139
v6.2.1:
commit: b8eb0da4121372b5d74a90fc36cba6a31f147f3c
result: SIGSEGV in a plain build, exit code 139Reproducer
PoC:
poc-java-stack-overflow-54000.javaRun:
./ctags -f /dev/null --sort=no poc-java-stack-overflow-54000.javaObserved result
In a plain build, ctags crashes with SIGSEGV.
Under ASan, this is reported as a stack overflow involving repeated recursion through the Java/C-family parser path:
ERROR: AddressSanitizer: stack-overflow
...
createTags()
nest()
createTags()
nest()
...The relevant frames are around:
parsers/c-based.c:3008 createTags()
parsers/c-based.c:2748 newStatement()Expected result
Malformed or excessively nested Java source input should not crash ctags. The parser should reject the input, stop parsing the file, or enforce a reasonable nesting/depth limit.
Impact
This is best described as uncontrolled recursion / stack exhaustion leading to a process crash. It is reachable from source file content supplied to ctags, so the practical impact is denial of service when indexing an untrusted repository or source file in editor, CI, or code-navigation workflows.
Notes
I have a small reproduction package with the PoC, plain/ASan logs for master and v6.2.1, and reproduction scripts. I can provide it if useful.
Source: universal-ctags/ctags