Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Integer parameters equal to 2^63 pass the range check in toInt and wrap to a negative number

Aberta Para iniciantes
#3,489 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 4 dias

@xiao115255 já está trabalhando nisso.

Desde 13/10/2026.

  • #3493 de @xiao115255 — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
82/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
go

Direção de pesquisa

Comece por toInt em pkg/github/params.go e examine os testes existentes de toInt em pkg/github. Execute go test ./pkg/github para ver a cobertura atual e, em seguida, adicione casos de limite em torno de 2^63. Verifique se eles retornam o erro de intervalo documentado e se os valores válidos dentro do intervalo continuam sendo convertidos.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Describe the bug

toInt in pkg/github/params.go is documented to reject "values outside the int range", but its upper bound check compares against math.MaxInt as a float:

if f > math.MaxInt || f < math.MinInt {
    return 0, fmt.Errorf("numeric value out of int range: %v", f)
}
return int(f), nil

math.MaxInt (2^63 - 1) cannot be represented as a float64 and rounds up to exactly 2^63. A value of 2^63 is therefore not greater than the bound, passes the check, and int(f) on an out-of-range float is implementation-defined in Go. On amd64 it produces math.MinInt (-9223372036854775808).

Any value that parses to 2^63, including the integer 9223372036854775807 itself, is accepted without an error and becomes a large negative number. This affects every tool that reads integers through RequiredInt, OptionalIntParam, OptionalIntParamWithDefault and OptionalPaginationParams (for example issue_number, pull_number, page, perPage). toInt64 is not affected because it uses a round-trip check.

Affected version

main at 07e2466, built from source (Go toolchain from go.mod, linux/amd64).

Steps to reproduce the behavior
  1. Add this test to pkg/github:

    package github
    
    import "testing"
    
    func TestToIntUpperBound(t *testing.T) {
        for _, v := range []any{"9223372036854775807", float64(9223372036854775807), "9223372036854775808", "1e19"} {
            n, err := OptionalIntParam(map[string]any{"pull_number": v}, "pull_number")
            t.Logf("%v -> %d, err=%v", v, n, err)
        }
    }
    
  2. Run go test ./pkg/github -run TestToIntUpperBound -v.

Expected vs actual behavior

Expected: every value at or above 2^63 is rejected with numeric value out of int range, as 1e19 already is.

Actual:

9223372036854775807    -> -9223372036854775808, err=<nil>
9.223372036854776e+18  -> -9223372036854775808, err=<nil>
9223372036854775808    -> -9223372036854775808, err=<nil>
1e19                   -> 0, err=parameter pull_number is not a valid number: numeric value out of int range: 1e+19

The negative value is then sent on to the GitHub API (for example as a pull request number or page) instead of being rejected locally with a clear parameter error.

Logs

Not applicable; the output above is from the test.

Possible Solution
  1. Make the upper bound exclusive at 2^63 (f >= -float64(math.MinInt)), or reuse the round-trip check that toInt64 already performs.
  2. Add the boundary values above to the existing toInt tests.
if f >= -float64(math.MinInt) || f < float64(math.MinInt) {
    return 0, fmt.Errorf("numeric value out of int range: %v", f)
}
return int(f), nil

I'm happy to send a PR.

Linguagem predominante
Go
Estrelas
33.6k
Forks
5.2k
Merge médio
2d 15h
PRs com merge (30d)
37

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de github/github-mcp-server

Todas as issues de github/github-mcp-server

Issues semelhantes

Mais issues de Go

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.