Guard OTLP attribute merge against allocation-size overflow#34117
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot create a helper to allocate array size to be reuse on every allocation site to avoid security warning. |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Fixed in e861607. I added a reusable |
There was a problem hiding this comment.
Pull request overview
This PR hardens slice/map preallocation across the pkg/workflow package to avoid int overflow when computing capacity hints (e.g., len(a)+len(b)), including the originally flagged OTLP custom attribute merge path.
Changes:
- Introduce
safeAllocationCapacity(...int)to safely sum allocation “capacity hints” and fall back to0on overflow. - Replace direct
len(x)+len(y)(+n)preallocation expressions withsafeAllocationCapacity(...)in multiple workflow components (OTLP merge, permissions, generators, validators). - Add unit tests covering boundary and overflow behavior for the new helper.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/workflow_import_merge.go | Use safe capacity hint when merging imported and main job pre-steps. |
| pkg/workflow/tools.go | Guard preallocation when merging types lists in defaults application. |
| pkg/workflow/threat_detection.go | Guard map preallocation when injecting threat-detection if conditions. |
| pkg/workflow/safe_output_handlers.go | Guard map preallocation when building handler lookup map. |
| pkg/workflow/safe_jobs_needs_validation.go | Guard slice preallocation when assembling cycle descriptions. |
| pkg/workflow/run_step_sanitizer.go | Guard map preallocation when rebuilding env maps during sanitization. |
| pkg/workflow/permissions.go | Guard map preallocation when building valid permission scope set. |
| pkg/workflow/permissions_validation.go | Guard slice preallocation when building scope list for fuzzy matching. |
| pkg/workflow/observability_otlp.go | Guard OTLP custom-attributes merge map preallocation. |
| pkg/workflow/network_firewall_validation.go | Guard slice preallocation when collecting ecosystem identifiers. |
| pkg/workflow/mcp_setup_generator.go | Guard preallocation for env key list + env map during setup YAML generation. |
| pkg/workflow/known_action_credentials.go | Guard map preallocation when merging known-action env var sets. |
| pkg/workflow/domains.go | Guard slice preallocation when building default domain lists. |
| pkg/workflow/concurrency.go | Guard slice preallocation when building concurrency expression parts. |
| pkg/workflow/compiler_safe_outputs.go | Guard map/slice preallocation when merging event types. |
| pkg/workflow/compiler_jobs.go | Guard slice preallocation when inserting pre-steps into step list. |
| pkg/workflow/compiler_aw_context.go | Guard slice preallocation when injecting workflow trigger inputs. |
| pkg/workflow/compiler_activation_job.go | Guard slice preallocation when injecting if after name. |
| pkg/workflow/awf_helpers.go | Guard map preallocation when building ecosystem domain map for scripts. |
| pkg/workflow/allocation_helpers.go | Add safeAllocationCapacity helper to prevent int overflow in capacity hints. |
| pkg/workflow/allocation_helpers_test.go | Add regression tests for overflow/boundary behavior of the helper. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 21/21 changed files
- Comments generated: 1
| // 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 { |
Code scanning flagged an integer-overflow risk in OTLP custom attribute merging. This change hardens the allocation path so extremely large input maps cannot overflow the capacity calculation and panic during merge.
Overflow guard in OTLP attribute merging
len(base) + len(override)capacity hint inmergeOTLPCustomAttributeswith a bounded helper.int; otherwise falls back to0so the merge remains correct without unsafe preallocation.Focused regression coverage
math.MaxIntboundary