Integer parameters equal to 2^63 pass the range check in toInt and wrap to a negative number
Les mainteneurs répondent en général sous 4 jours
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 82/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- go
- Domaine
- backend-api-design
Piste de recherche
Commence par toInt dans pkg/github/params.go et examine les tests existants de toInt dans pkg/github. Exécute go test ./pkg/github pour voir la couverture actuelle, puis ajoute des cas limites autour de 2^63. Vérifie qu’ils renvoient l’erreur de plage documentée et que les valeurs valides dans la plage sont toujours converties.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
-
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) } } -
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
- Make the upper bound exclusive at 2^63 (
f >= -float64(math.MinInt)), or reuse the round-trip check thattoInt64already performs. - Add the boundary values above to the existing
toInttests.
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.
- Langage dominant
- Go
- Étoiles
- 33.6k
- Forks
- 5.2k
- Merge moyen
- 2 j 15 h
- PR mergées (30 j)
- 37
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de github/github-mcp-server
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
github/github-mcp-server#3475 ·
Les mainteneurs répondent en général sous 4 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
github/github-mcp-server#3450 ·
Les mainteneurs répondent en général sous 4 jours
-
request ai review
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
github/github-mcp-server#3439 ·
Les mainteneurs répondent en général sous 4 jours
-
get_job_logs with failed_only misses failed jobs after the first 30 jobs of a runPeut-être pris @jayhemnani9910 l’a pris il y a 8 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
github/github-mcp-server#3428 ·
Les mainteneurs répondent en général sous 4 jours
-
create_or_update_file writes to the wrong file when the path contains # or ?Peut-être pris @jayhemnani9910 l’a pris il y a 8 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
github/github-mcp-server#3427 ·
Les mainteneurs répondent en général sous 4 jours
Toutes les issues de github/github-mcp-server
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
praetorian-inc/augustus#334 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
-
TestTOMLBigFileParsesInLinearTime: a 1s wall-clock bound on a 3 MB parse fails under load (1.27s)Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 80/100
peasant-labs/village#293 ·
Les mainteneurs répondent en général sous 1 jour