Skip to content

fix(reliability): make goroutine-in-loop detection linear to avoid quadratic AST walks - #130

Merged
alxxjohn merged 1 commit into
mainfrom
alexj/propose-fix-for-reliability-scan-vulnerability
Aug 18, 2026
Merged

fix(reliability): make goroutine-in-loop detection linear to avoid quadratic AST walks#130
alxxjohn merged 1 commit into
mainfrom
alexj/propose-fix-for-reliability-scan-vulnerability

Conversation

@alxxjohn

Copy link
Copy Markdown
Contributor

Motivation

  • The previous implementation called isInsideLoop (which performed a full ast.Inspect over the function body) for every *ast.GoStmt, producing quadratic behavior and allowing attacker-controlled source to cause excessive CPU usage during reliability scans.
  • Reliability checks are enabled by some default profiles, so this path is reachable in hardened CI and needed a linear-time fix to prevent CI DoS.

Description

  • Replace repeated full-function traversals with loop nesting tracking performed during the existing ast.Inspect pass by adding loopDepth and loopStack and checking loopDepth > 0 for goroutine-in-loop classification.
  • Remove the expensive helper isInsideLoop from reliability_go_helpers.go and update functionReliabilityFindings in reliability_go.go to use the in-pass loop depth check instead of extra walks.
  • Preserve existing rule semantics and finding generation (reliability.unbounded-work and related checks) while changing only the detection mechanism to be linear in AST size.

Testing

  • Ran formatting with gofmt -w internal/codeguard/checks/reliability/*.go and it completed successfully.
  • Executed go test ./tests/checks and the test suite ran successfully in this environment.
  • Executed go test ./internal/codeguard/checks/reliability which reported there are no test files for that package, so no package-local tests were run.
  • Ran git diff --check to ensure no whitespace or trivial issues and it reported no problems.

Codex Task

@alxxjohn
alxxjohn merged commit 23f7558 into main Aug 18, 2026
16 checks passed
@alxxjohn
alxxjohn deleted the alexj/propose-fix-for-reliability-scan-vulnerability branch August 18, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant