Skip to content

fix(normalizer): validate numeric float64 inputs in typed read normalizer (#3762) - #3785

Open
yunusarda-sudo wants to merge 6 commits into
github:mainfrom
yunusarda-sudo:fix/validate-numeric-pagination-bounds
Open

yunusarda-sudo wants to merge 6 commits into
github:mainfrom
yunusarda-sudo:fix/validate-numeric-pagination-bounds

Conversation

@yunusarda-sudo

Copy link
Copy Markdown

Resolves #3762

Summary of Changes

In normalizeTypedReadArguments, pagination parameters (page and perPage) were previously only range-checked when provided as JSON strings (if text, ok := number.(string)). When arguments were supplied as JSON numbers, they were unmarshaled into number.(float64) and bypassed the integer and range validation in inSignedIntRange.

When an out-of-range integer (e.g. 9223372036854775808 or numbers below -2^63) or a floating-point value was provided as a raw JSON number, it bypassed the normalizer and subsequently failed in json.Unmarshal with a raw Go decode error (leaking internal type names such as github.ListCommitsInput.page of type int).

  1. Unified validation (pkg/github/typed_read_normalizers.go):

    • Extract numeric value uniformly for both string and float64 input types.
    • Reject math.IsNaN, math.IsInf, non-integers (parsed != math.Trunc(parsed)), and out-of-range values (!inSignedIntRange(parsed, strconv.IntSize)) with a clean parameter <field> is not a valid number error.
    • Preserve zero-page and zero-perPage deletion behavior on the validated integer value.
    • Re-serialize as normalized integer.
  2. Regression tests (pkg/github/typed_search_outputs_test.go):

    • Added test cases covering raw JSON numeric out-of-range values and non-integers (1.5) in TestNormalizeTypedReadArgumentsRejectsOutOfRangeIntegers.

Reported-by: Rafe Walker

Verification

  • Ran go test -v -run TestNormalizeTypedReadArguments ./pkg/github (all passed).
  • Ran go test ./pkg/github (all package tests passed).

…izer (github#3762)

The typed-read argument normalizer only checked string values for out-of-range
and non-integer values, letting raw float64 numbers bypass validation and fail
in json.Unmarshal with a raw Go struct decode error (leaking internal types).

Validate both string and float64 number inputs uniformly against
inSignedIntRange and integers, rejecting out-of-range numbers cleanly.

Reported-by: Rafe Walker
Signed-off-by: Yunus Ardaguney <yunusarda-sudo@users.noreply.github.com>
@yunusarda-sudo
yunusarda-sudo requested a review from a team as a code owner November 9, 2026 22:56
Copilot AI adaptive review requested due to automatic review settings November 9, 2026 22:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The numeric range check can accept an out-of-range page value after float64 rounding, requiring lossless token validation and a regression test for -2^63-1.

1 open issue
What changed in this PR

This PR updates the typed-read argument normalizer to validate raw numeric pagination inputs alongside numeric strings, addressing validation and decode-error handling reported in #3762.

Changes:

  • Applies shared integer and range checks to string and numeric page/perPage inputs.
  • Serializes validated values as integers while preserving zero-value handling.
  • Adds regression cases for raw out-of-range numbers and fractional input.
File Description
pkg/​github/​typed_search_outputs_test.go Adds numeric boundary and fractional-input rejection tests.
pkg/​github/​typed_read_normalizers.go Unifies pagination validation and integer serialization.

Review effort: Balanced (auto)

Comment thread pkg/github/typed_read_normalizers.go Outdated
Comment on lines +56 to +59
if math.IsNaN(parsed) || math.IsInf(parsed, 0) || parsed != math.Trunc(parsed) || !inSignedIntRange(parsed, strconv.IntSize) {
return nil, fmt.Errorf("parameter %s is not a valid number", field)
}
if field == "perPage" {
if parsed, ok := number.(float64); ok && parsed == 0 {
delete(args, field)
continue
}
if parsed, ok := number.(int); ok && parsed == 0 {
delete(args, field)
continue
}
intVal := int(parsed)
yunusarda-sudo and others added 5 commits November 15, 2026 15:02
…sion

Decode with UseNumber and parse integer tokens exactly, so values such as
-9223372036854775809 are rejected instead of rounding into range. Decimal
and exponent forms are checked as exact rationals after bounding token
length and exponent.

@SoulmatelynchVFX SoulmatelynchVFX left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The case string branch still goes through strconv.ParseFloat and parsed != math.Trunc(parsed) (line 82), and intVal = int(parsed) (line 85). That check catches a fraction, not a lost integer digit: binary64 cannot hold integers above 2^53, so {"perPage":"9007199254740993"} parses to 9007199254740992, passes both the trunc and the range check, and is serialized as 9007199254740992 without an error. The same value as a bare number token is kept exactly by exactIntegerToken, and your new TestNormalizeTypedReadArgumentsPreservesExactNumbers lists 9007199254740993 for perPage, so the two input forms now disagree.

I checked the rounding rather than the parser: float("9007199254740993") == 9007199254740992.0 and p == math.trunc(p) is true, float("9007199254740995") rounds up to 9007199254740996. Python's float() and Go's ParseFloat are both correctly rounded binary64, so the same token gives the same bits. I did not run go test (no Go toolchain here), so inSignedIntRange's boundary form and the actual perPage ceiling on the server side are unverified; I only confirmed that the 2^53 band passes the code path above without an error.

Not fixed by this PR and probably out of scope, but worth deciding: if the string branch is meant to keep tolerating "25.0", one option is to try ParseInt first and fall back to exactIntegerToken for the decimal/exponent forms, which would leave a bare float path only where it is deliberate.

AI-assisted review draft; the finding comes from reading the branch and IEEE-754 rounding, not from running the suite.

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.

Advertised page/perPage bounds are not enforced in list_commits, get_commit, actions_list and list_gists, and -2^63 returns a raw Go decode error

3 participants