Skip to content

Guard GraphQL PR number conversion against int32 overflow#56

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-code-scanning-alerts
Draft

Guard GraphQL PR number conversion against int32 overflow#56
Copilot wants to merge 2 commits intomainfrom
copilot/fix-code-scanning-alerts

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 21, 2026

This PR addresses the CodeQL alert on unsafe integer downcast when passing PR numbers into GraphQL query variables. The change ensures int values are validated before converting to graphql.Int (int32-backed).

  • What changed

    • Added a narrow conversion helper in internal/github/github.go:
      • toGraphQLInt(n int) (graphql.Int, error)
      • Enforces math.MinInt32 <= n <= math.MaxInt32
    • Updated FindPRByNumber to use the validated conversion instead of direct cast.
  • Behavioral impact

    • Out-of-range PR numbers now fail fast with a clear error instead of risking truncation/overflow during conversion.
  • Focused coverage

    • Added unit tests in internal/github/github_test.go for:
      • successful in-range conversion
      • error on out-of-range conversion
func toGraphQLInt(n int) (graphql.Int, error) {
	if n < math.MinInt32 || n > math.MaxInt32 {
		return 0, fmt.Errorf("number %d is out of GraphQL Int range", n)
	}
	return graphql.Int(n), nil
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /tmp/go-build2513184261/b287/cmd.test /tmp/go-build2513184261/b287/cmd.test -test.testlogfile=/tmp/go-build2513184261/b287/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� g_.a 0.1-go1.25.7.lin--64 ux-amd64/pkg/tool/linux_amd64/compile user.name (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix code scanning alert #3 Guard GraphQL PR number conversion against int32 overflow Apr 21, 2026
Copilot AI requested a review from skarim April 21, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants