Guard allocation size calculations flagged by CodeQL - #55480
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
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
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
❌ Design Decision Gate 🏗️ failed during design decision gate check. Warning Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding. What happenedThe threat detection engine failed to produce results. Review the workflow run logs for details.
|
|
✅ PR Code Quality Reviewer completed the code quality review. Completed PR review for #55480. No GitHub write action was needed because I found no actionable changed-line issues warranting review comments or a blocking review.
|
|
✅ Ponytail Reviewer completed successfully!
|
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs, /tdd, and /codebase-design — COMMENT (no blocking issues, minor improvements noted).
📋 Key Themes & Highlights
Key Themes
- Silent overflow fallback — the
typeutilversion drops theallocationLog.Printfpresent in the oldworkflowpackage. Consider a comment or call-site logging for observability. - Test branch coverage —
TestExperimentVariantCountscovers the main path; the two early-exit branches (!includeDeclared,cfg == nil) are untested. - Test file naming —
allocation_helpers_test.goshould match the source file nameallocation.go→allocation_test.go.
Positive Highlights
- ✅ Excellent extraction of
safeAllocationCapacityintopkg/typeutil— correct response to the prior review comment. - ✅ Variadic signature is clean and extensible.
- ✅ Overflow boundary tests (
math.MaxIntedges) are thorough. - ✅ Consistent rollout across all 20+ call sites with no functional changes.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet46 · 29 AIC · ⌖ 9.99 AIC · ⊞ 7.6K
Comment /matt to run again
Comments that could not be inline-anchored
pkg/typeutil/allocation.go:13
[/diagnosing-bugs] Silent overflow fallback: the old pkg/workflow/allocation_helpers.go logged on overflow (allocationLog.Printf(...)); the new typeutil version drops that signal entirely. If a caller ever hits this path in production, there will be no trace in logs.
<details>
<summary>💡 Suggestion</summary>
Either add a comment explaining the intentional omission (e.g. import-cycle constraints), or thread a debug log through at the call site. The overflow case is rare but actionab…
pkg/cli/experiments_analyze_statistics_test.go:43
[/tdd] TestExperimentVariantCounts only tests the includeDeclared=true with a non-nil cfg path. The two short-circuit branches (!includeDeclared and cfg == nil) return exp.Variants directly and are untested here.
<details>
<summary>💡 Suggested additions</summary>
t.Run("returns exp.Variants when includeDeclared=false", func(t *testing.T) {
got := experimentVariantCounts(exp, cfg, false)
assert.Equal(t, exp.Variants, got)
})
t.Run("returns exp.Variants when cfg …
</details>
<details><summary>pkg/typeutil/allocation_helpers_test.go:1</summary>
**[/codebase-design]** Minor naming inconsistency: the source file is `pkg/typeutil/allocation.go` but the test file is named `allocation_helpers_test.go`. Go convention is `allocation_test.go` to match the source.
@copilot please address this.
</details>There was a problem hiding this comment.
Clean and well-structured refactor. Moving safeAllocationCapacity to pkg/typeutil as exported SafeAllocationCapacity is the right call — it makes the guard reusable across packages without circular dependencies.
The one behavioral change is removal of the overflow log (allocationLog.Printf). This is appropriate for a utility package that should not carry a logger dependency, and overflow in these allocation hints only occurs at astronomically large slice sizes where the 0-fallback is safe.
Tests are thorough, t.Parallel() is correctly added, and all callers are updated. LGTM.
🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · copilot · sonnet46 · 23.6 AIC · ⌖ 8.99 AIC · ⊞ 6.2K
There was a problem hiding this comment.
One small simplification opportunity: a shared helper for this single overflow-check pattern is more abstraction than the fix needs. net: -14 lines possible.
Generated by ✂️ Ponytail Reviewer for #55480 · codex · mai10 · 5.19 AIC · ⌖ 1.3 AIC · ⊞ 18.3K
Comment /ponytail to run again
| // SafeAllocationCapacity returns the summed capacity hint when it fits in int. | ||
| // When the total would overflow, it falls back to 0 so callers can skip | ||
| // preallocation without changing correctness. | ||
| func SafeAllocationCapacity(parts ...int) int { |
There was a problem hiding this comment.
pkg/typeutil/allocation.go:L8: yagni: exported varargs helper for a single overflow-check pattern. Inline the small sum/overflow guard in the few sites that need it.
There was a problem hiding this comment.
Kept the shared helper because the maintainer requested moving this overflow guard into a helper package, and the pattern now has multiple call sites. Added ADR-55480 to document the decision and tradeoff.
There was a problem hiding this comment.
Pull request overview
Centralizes overflow-safe allocation sizing and applies it to CodeQL-flagged paths.
Changes:
- Adds and tests
typeutil.SafeAllocationCapacity. - Migrates workflow allocation hints to the shared helper.
- Protects experiment variant-count allocation from overflow.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/workflow_import_merge.go |
Uses safe merged-step capacity. |
pkg/workflow/tools.go |
Guards event-type allocation hints. |
pkg/workflow/threat_detection_steps.go |
Guards cloned-map capacity. |
pkg/workflow/safe_output_handlers.go |
Guards handler-map capacity. |
pkg/workflow/safe_jobs_needs_validation.go |
Guards cycle-path capacity. |
pkg/workflow/run_step_sanitizer.go |
Guards environment-map capacity. |
pkg/workflow/permissions.go |
Guards permission-map capacity. |
pkg/workflow/permissions_validation.go |
Guards permission-name capacity. |
pkg/workflow/observability_otlp.go |
Guards merged-map capacity. |
pkg/workflow/network_firewall_validation.go |
Guards ecosystem-list capacity. |
pkg/workflow/mcp_setup_safe_outputs.go |
Guards environment-map capacity. |
pkg/workflow/known_action_credentials.go |
Guards credential-map capacity. |
pkg/workflow/domains.go |
Guards domain-list capacities. |
pkg/workflow/concurrency.go |
Guards concurrency-key capacities. |
pkg/workflow/compiler_job_step_helpers.go |
Guards inserted-step capacities. |
pkg/workflow/compiler_builtin_job_augmentation.go |
Guards augmented-step capacity. |
pkg/workflow/compiler_aw_context.go |
Guards generated-line capacity. |
pkg/workflow/compiler_activation_job.go |
Guards condition-injection capacity. |
pkg/workflow/awf_helpers.go |
Guards ecosystem-map capacity. |
pkg/workflow/allocation_helpers.go |
Removes superseded local helper. |
pkg/workflow/allocation_helpers_test.go |
Removes relocated helper tests. |
pkg/typeutil/allocation.go |
Adds shared overflow-safe helper. |
pkg/typeutil/allocation_helpers_test.go |
Covers valid, overflow, and negative inputs. |
pkg/cli/experiments_analyze_statistics.go |
Fixes flagged map capacity calculation. |
pkg/cli/experiments_analyze_statistics_test.go |
Verifies variant-count behavior. |
Review details
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 25/25 changed files
- Comments generated: 1
- Review effort level: Balanced
| _ "embed" | ||
| "encoding/json" | ||
| "fmt" | ||
| "github.com/github/gh-aw/pkg/typeutil" |
There was a problem hiding this comment.
Addressed in 3d2f4a8 by moving pkg/typeutil into the repository import group in pkg/workflow/domains.go.
|
Please do one focused follow-up pass:
I also attempted a branch refresh for this PR in this run. Run: https://github.com/github/gh-aw/actions/runs/32781466813
|
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Addressed in 38b0a59: added a side-effect-free rationale comment to
Addressed with 3d2f4a8 and 38b0a59: fixed the goimports issue in |
CodeQL flagged potential
go/allocation-size-overflowpaths where summedlen(...)values fed allocation sizes. Large or malformed inputs could overflow capacity calculations and cause unexpected allocation behavior.Overflow-safe allocation hints
safeAllocationCapacity(...).pkg/workflow/tools.goandpkg/cli/experiments_analyze_statistics.go.CLI allocation helper
Boundary coverage
Example: