Skip to content

fix(security): track identifier lines linearly - #110

Merged
alxxjohn merged 1 commit into
mainfrom
alexj/propose-fix-for-quadratic-identifier-bug
Aug 18, 2026
Merged

fix(security): track identifier lines linearly#110
alxxjohn merged 1 commit into
mainfrom
alexj/propose-fix-for-quadratic-identifier-bug

Conversation

@alxxjohn

Copy link
Copy Markdown
Contributor

Motivation

  • The identifiers-in-source routine computed each identifier's line by counting newlines from the file start for every match, producing O(n^2) work on identifier-dense inputs and enabling CI/scan denial-of-service.
  • The goal is to preserve existing naming checks while eliminating repeated scanning of growing prefixes so scans remain available for untrusted repositories.

Description

  • Rewrote identifiersInSource in internal/codeguard/checks/quality/quality_precision_workstreams_cd.go to maintain a running line counter and only strings.Count the non-overlapping slice between consecutive matches, making line computation linear-time.
  • Added internal/codeguard/checks/quality/quality_precision_workstreams_cd_test.go with TestIdentifiersInSourceTracksLines to assert correct line numbers across same-line identifiers, blank lines, and subsequent line transitions.
  • Preserved identifier names and output shape so downstream naming checks (e.g., roleSuffixOveruseFinding, crossLayerInconsistencyFinding) continue to operate without behavior changes.

Testing

  • Formatted the modified files with gofmt and ran go test ./internal/codeguard/checks/quality ./tests/checks, and the test suites completed successfully.
  • Ran go test specifically for the internal/codeguard/checks/quality package and observed the new unit test pass.
  • Attempted szr-wrapped test command but szr is not installed in this environment, and equivalent direct go test invocations were used instead and passed.

Codex Task

@alxxjohn
alxxjohn merged commit dc348e8 into main Aug 18, 2026
16 checks passed
@alxxjohn
alxxjohn deleted the alexj/propose-fix-for-quadratic-identifier-bug branch August 22, 2026 20: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