Skip to content

fix: Potential fix for code scanning alert no. 20: Slice memory allocation with excessive size value#8

Merged
skyoo2003 merged 2 commits intomainfrom
alert-autofix-20
Apr 20, 2026
Merged

fix: Potential fix for code scanning alert no. 20: Slice memory allocation with excessive size value#8
skyoo2003 merged 2 commits intomainfrom
alert-autofix-20

Conversation

@skyoo2003
Copy link
Copy Markdown
Owner

Potential fix for https://github.com/skyoo2003/devcloud/security/code-scanning/20

Add strict bounds validation for MinCount in internal/services/ec2/provider.go within handleRunInstances:

  • Keep existing behavior defaulting to count = 1.
  • Parse MinCount as today, but reject invalid/non-positive values with a BadRequest-style EC2 XML error.
  • Enforce a maximum allowed instance count constant (e.g., 1000) and reject requests above it.
  • Only pass validated count to p.store.RunInstances(...).

This is the best single fix because it addresses the tainted input at the trust boundary (request parsing), preserves existing functionality for valid requests, and prevents excessive allocations at the sink in RunInstances without requiring broader architectural changes.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

… with excessive size value

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@github-actions github-actions Bot added the services AWS service implementations label Apr 19, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 19, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds strict validation for the EC2 RunInstances MinCount parameter to prevent excessive slice allocations by enforcing positive integer bounds and a maximum batch size before invoking RunInstances.

File-Level Changes

Change Details Files
Introduce strict MinCount validation and a maximum batch size limit in handleRunInstances to guard the RunInstances call.
  • Extend EC2 provider-level constants to include a maxRunInstancesBatchCount limit set to 1000.
  • Change MinCount parsing logic to treat non-integer or non-positive values as errors and return an EC2 XML InvalidParameterValue BadRequest response.
  • Add an upper bound check against maxRunInstancesBatchCount and return an EC2 XML InvalidParameterValue BadRequest response if exceeded.
  • Ensure only the validated MinCount value is used as the count passed into p.store.RunInstances.
internal/services/ec2/provider.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@skyoo2003 skyoo2003 self-assigned this Apr 19, 2026
@skyoo2003 skyoo2003 changed the title Potential fix for code scanning alert no. 20: Slice memory allocation with excessive size value fix: Potential fix for code scanning alert no. 20: Slice memory allocation with excessive size value Apr 19, 2026
@skyoo2003 skyoo2003 marked this pull request as ready for review April 19, 2026 18:51
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider making maxRunInstancesBatchCount either configurable or at least documenting why 1000 was chosen so future maintainers understand the rationale for this limit.
  • The new InvalidParameterValue responses for MinCount should be checked against existing EC2 error conventions in this service (e.g., status code and message shape) to ensure they are consistent with how other parameter validation errors are reported.
  • You now strictly validate MinCount but still ignore MaxCount; it may be worth validating MaxCount in a similar way (or explicitly noting why it is not used) to avoid inconsistent behavior and future confusion.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider making `maxRunInstancesBatchCount` either configurable or at least documenting why `1000` was chosen so future maintainers understand the rationale for this limit.
- The new `InvalidParameterValue` responses for `MinCount` should be checked against existing EC2 error conventions in this service (e.g., status code and message shape) to ensure they are consistent with how other parameter validation errors are reported.
- You now strictly validate `MinCount` but still ignore `MaxCount`; it may be worth validating `MaxCount` in a similar way (or explicitly noting why it is not used) to avoid inconsistent behavior and future confusion.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

- Document maxRunInstancesBatchCount rationale (matches AWS EC2 default)
- Add MaxCount validation with same checks as MinCount
@github-actions github-actions Bot added the bug Something isn't working label Apr 20, 2026
@skyoo2003 skyoo2003 merged commit 12d25b7 into main Apr 20, 2026
10 checks passed
@skyoo2003 skyoo2003 deleted the alert-autofix-20 branch April 20, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working services AWS service implementations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant