Repository navigation
Avoid allocation-size overflow in AWF model policy union - #66646
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Ponytail Reviewer completed successfully! Lean already. Ship.
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft. No ADR enforcement needed for PR #66646: no 'implementation' label (has_implementation_label=false) and only 50 added lines in business logic directories across 2 files, below the 100-line default threshold (requires_adr_by_default_volume=false, no custom .design-gate.yml).
|
There was a problem hiding this comment.
🔵 Needs a closer look
The security fix appears sound, but the stated human-review requirement and unverified CodeQL alert closure require final human validation.
0 open findings
What changed in this PR
Removes overflow-prone capacity arithmetic from AWF model-policy union logic while preserving ordered deduplication and non-nil results.
Changes:
- Removes combined-length slice and map preallocation.
- Adds regression coverage for ordering, duplicates, input independence, and duplicate-heavy inputs.
| File | Description |
|---|---|
pkg/workflow/awf_config_policy.go |
Uses incremental allocation for policy unions. |
pkg/workflow/awf_config_test.go |
Adds allocation-safety and behavior tests. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
Verdict
No blocking issue found in this patch.
Review notes
The fix is appropriately surgical: it removes the overflow-prone combined preallocation while preserving ordered de-duplication semantics, and the added tests cover empty inputs, duplicates, ordering, and input immutability. I also checked the new duplicate-heavy regression case; it does touch an implementation detail via `cap(got)`, but the assertion is loose enough that I do not consider it a merge blocker.🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 18.6 AIC · ⌖ 5.25 AIC · ⊞ 19.6K
Comment /review to run again
There was a problem hiding this comment.
Impeccable Review — harden / audit
Change type: bug_fix (CodeQL allocation-overflow fix, #66614)
Summary: unionModelPolicyRules no longer preallocates capacity from len(local)+len(override), eliminating the integer-overflow/huge-allocation risk CodeQL flagged. Behavior is preserved (dedup + first-occurrence ordering), and the new tests cover empty inputs, duplicates, ordering, independent output storage (no aliasing of input slices), and a duplicate-heavy 10k-element case asserting cap(got) < len(local).
Findings: No blocking issues. The fix is minimal, correct, and verified by go test ./pkg/workflow/... -run TestUnionModelPolicyRules -v (all passing).
Notes (non-blocking)
intersectModelPolicyRulesstill preallocatesmake([]string, 0, len(override)), which is safe (bounded by a single slice length, not a sum), so no change needed there.- A few other call sites in the package (e.g.
imports.go:219-220,compiler_builtin_job_augmentation.go:335-336) use the samelen(a)+len(b)capacity-hint pattern. They're out of scope for this PR but could be worth a follow-up sweep if the same CodeQL rule flags them later.
🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · copilot · sonnet50 · 21.8 AIC · ⌖ 13.2 AIC · ⊞ 8.1K
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs and /tdd — this is a narrowly scoped fix with solid regression coverage, approving.
📋 Analysis
Root cause addressed correctly
The CodeQL alert flagged make([]string, 0, len(local)+len(override)) and make(map[string]struct{}, len(local)+len(override)) in unionModelPolicyRules — these capacity hints are derived from two independently-sized, attacker-influenceable slices (workflow frontmatter + env policy) and could overflow/panic on pathological inputs. The fix drops both capacity hints entirely, letting Go's slice/map growth handle sizing incrementally. This addresses the root cause (unchecked summed capacity) rather than just suppressing the symptom.
Test coverage (/tdd)
The new tests are a good set of specifications:
TestUnionModelPolicyRulescovers empty/empty, empty-override, empty-local, and dedup-with-order-preservation — plus an aliasing check that mutating the result doesn't mutate the inputs (confirms independent storage, a good regression guard given the previous code's shared-capacity pattern).TestUnionModelPolicyRules_DuplicateHeavyInputsdirectly encodes the fix's intent:cap(got) < len(local)proves capacity now grows with unique output size rather than combined input length — this is exactly the kind of test that would have caught the original bug and will catch any regression that reintroduces combined-length preallocation.
Minor observation (non-blocking)
intersectModelPolicyRules (unchanged in this PR) still does make([]string, 0, len(override)) — a single-slice capacity hint, so it doesn't have the same two-input-sum overflow shape. Worth a quick confirmatory look in a follow-up if override can also grow unbounded, but it's out of scope for this fix and not required here.
Positive highlights
- ✅ Correctly scoped: touches only the two lines CodeQL flagged, no unrelated refactoring
- ✅ Tests assert both behavior (
want) and capacity growth characteristics, not just functional output - ✅ Input-immutability check (mutating
got[0]and asserting originals unchanged) is a nice touch confirming no accidental aliasing
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 23.9 AIC · ⌖ 14.4 AIC · ⊞ 10.1K
Comment /matt to run again
🧪 Test Quality Sentinel Report✅ Test Quality Score: 92/100 — Excellent
📊 Metrics (5 tests)
Quality Highlights✨ Exceptional test design:
Verdict
|
There was a problem hiding this comment.
✅ Test Quality Sentinel: 92/100. 0% implementation tests (threshold: 30%). All 5 tests are high-value behavioral contracts with exceptional regression coverage for the CodeQL allocation-size fix.
🧪 Test quality analysis by Test Quality Sentinel · copilot · haiku45 · 25.1 AIC · ⌖ 6.73 AIC · ⊞ 8.2K
Comment /review to run again
|
🎉 This pull request is included in a new release. Release: |
Two high-severity CodeQL alerts flagged unchecked
len(local)+len(override)capacity calculations inawf_config_policy.go. Local policy sizes derive from workflow frontmatter, meeting the issue’s human-review trigger.