Skip to content

fix: reject float32 overflow in resolved numeric values - #677

Open
dailyun wants to merge 1 commit into
alecthomas:masterfrom
dailyun:codex/reject-resolved-float32-overflow
Open

dailyun wants to merge 1 commit into
alecthomas:masterfrom
dailyun:codex/reject-resolved-float32-overflow

Conversation

@dailyun

@dailyun dailyun commented Oct 21, 2026

Copy link
Copy Markdown

kong.JSON resolves numbers as float64. A value such as 1e40 is then silently stored as +Inf in a float32 field, while passing the same value through --value=1e40 already returns an error.

Reject finite resolved values that overflow to infinity when narrowed to float32. Keep float64 fields, explicit infinities from custom resolvers, and values just above MaxFloat32 that still round to a finite value working as before.

Minimal reproduction:

var cli struct{ Value float32 }
resolver, _ := kong.JSON(strings.NewReader(`{"value": 1e40}`))
parser, _ := kong.New(&cli, kong.Resolvers(resolver))
_, err := parser.Parse(nil)
// Before: err == nil, cli.Value == +Inf. After: a float32 range error.

Validation on Go 1.26.7/macOS arm64:

  • Positive and negative JSON overflow cases fail against unchanged source and pass with the fix.
  • Added controls for CLI overflow, rounding at the float32 limit, large valid float64 values and explicit resolved infinities.
  • go test ./... -count=1, go test -race ./... -count=1, and the pinned golangci-lint 1.64.5 pass.
  • go vet -structtag=false ./... passes (the project intentionally supports bare struct-tag keys).

No public API or dependency changes. Implemented and tested with Codex through the dailyun account; no independent human review is claimed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T09:53:55.025534Z 12d9c60 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

1 participant