Skip to content

Cap rule-stats history reads to prevent memory exhaustion - #141

Merged
alxxjohn merged 3 commits into
mainfrom
alexj/fix-unbounded-rule-stats-history-read
Aug 19, 2026
Merged

Cap rule-stats history reads to prevent memory exhaustion#141
alxxjohn merged 3 commits into
mainfrom
alexj/fix-unbounded-rule-stats-history-read

Conversation

@alxxjohn

Copy link
Copy Markdown
Contributor

Motivation

  • The rule-stats history loader previously used os.ReadFile with no size cap, allowing a repository-controlled history file to cause the process to buffer an arbitrarily large file and exhaust CI memory.
  • The fix aims to prevent OOM by reusing the existing size-capped cache reader so oversized or malicious history files are treated as cache-misses while preserving existing missing/malformed/version-mismatch semantics.

Description

  • Replace the uncapped os.ReadFile/json.Unmarshal path in LoadRuleStatsHistory with the shared size-capped loader cachefile.Load, and add the cachefile import.
  • Keep the same behavior for blank paths, missing files, malformed JSON, and version mismatches while enforcing the read cap.
  • Add a regression test TestLoadRuleStatsHistoryRejectsOversizedFile in tests/support/rule_stats_history_test.go that writes a file larger than the 32 MiB cap and asserts the loader returns empty history.

Testing

  • go test ./tests/support succeeded.
  • go test ./internal/codeguard/runner/support succeeded.
  • go test ./tests/cli was executed together with the support tests and succeeded (tests reported OK/cached).
  • git diff --check and repository status checks completed with no issues.

Codex Task

@alxxjohn
alxxjohn merged commit 515b291 into main Aug 19, 2026
16 checks passed
@alxxjohn
alxxjohn deleted the alexj/fix-unbounded-rule-stats-history-read branch August 19, 2026 17:04
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