Skip to content

Respect native integer width when decoding form values - #79

Open
vitalivo wants to merge 1 commit into
go-playground:masterfrom
vitalivo:fix/native-integer-overflow
Open

vitalivo wants to merge 1 commit into
go-playground:masterfrom
vitalivo:fix/native-integer-overflow

Conversation

@vitalivo

Copy link
Copy Markdown

This replaces #78, which was accidentally closed and its source fork deleted. The implementation is unchanged; the original discussion and reviews remain linked there.


Fixes Or Enhances

On 32-bit targets, decoding 2147483648 into int succeeds with -2147483648, and decoding 4294967296 into uint succeeds with zero. The shared int/int64 and uint/uint64 branches always parse with a 64-bit limit before reflection truncates the value.

Use the destination type's bit width for parsing. Regression tests verify both signed overflow directions, unsigned overflow, unchanged destination values on error, valid native boundaries, and values that still fit explicit 64-bit fields.

  • Tests exist or have been written that cover this particular change.

Validation: the three overflow cases fail on linux/386 before the fix. Full suites pass with GOARCH=386 go test -cover ./... and go test -race -cover ./... on amd64 (99.8% coverage). go vet ./... passes and golangci-lint reports no new issues.

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Integer map keys still parse native values with a 64-bit limit and can silently wrap on 32-bit targets.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Updates integer decoding to respect the destination type’s native width.

Changes:

  • Uses v.Type().Bits() for native integer parsing.
  • Adds 32-bit overflow and boundary regression tests.
File Description
decoder.go Applies native-width parsing to scalar integer fields.
decoder_test.go Adds native integer overflow and boundary tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread decoder.go
}
var u64 uint64
if u64, err = strconv.ParseUint(arr[idx], 10, 64); err != nil {
if u64, err = strconv.ParseUint(arr[idx], 10, v.Type().Bits()); err != nil {
Comment thread decoder.go
}
var i64 int64
if i64, err = strconv.ParseInt(arr[idx], 10, 64); err != nil {
if i64, err = strconv.ParseInt(arr[idx], 10, v.Type().Bits()); err != nil {
@deankarn

Copy link
Copy Markdown
Contributor

@vitalivo if you can address the above 🙏 I'll look at merging

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.

3 participants