Skip to content

fix: reject numeric request parameters which overflow the destination Go type - #1096

Open
leonklingele wants to merge 4 commits into
danielgtaylor:mainfrom
leonklingele:fix/int-overflow-error
Open

fix: reject numeric request parameters which overflow the destination Go type#1096
leonklingele wants to merge 4 commits into
danielgtaylor:mainfrom
leonklingele:fix/int-overflow-error

Conversation

@leonklingele

Copy link
Copy Markdown
Contributor

Numeric request parameters are parsed using 64 bit parsing regardless of the
destination Go type, then assigned through reflection.

This can silently change user input rather than returning a 4xx validation error.

… Go type

Numeric request parameters are parsed using 64 bit parsing regardless of the
destination Go type, then assigned through reflection.

This can silently change user input rather than returning a 4xx validation error.
Copilot AI lite review requested due to automatic review settings August 8, 2026 13:46
@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.20%. Comparing base (198225e) to head (3323128).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1096   +/-   ##
=======================================
  Coverage   93.20%   93.20%           
=======================================
  Files          23       23           
  Lines        4988     4992    +4     
=======================================
+ Hits         4649     4653    +4     
  Misses        272      272           
  Partials       67       67           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Pull request overview

This PR tightens request-parameter numeric parsing so that values are parsed using the destination Go type’s bit-size (via reflection) rather than always parsing as 64-bit first, preventing silent overflow/coercion and returning a client validation error instead.

Changes:

  • Parse signed/unsigned integers and floats using the destination type’s bit width (reflect.Type.Bits()), rejecting overflows.
  • Apply the same bit-size-aware parsing in both the “set field” helper and the main request parameter parsing path.
  • Add a regression test covering query parameter overflow for a narrow integer type (int8).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
huma.go Parse numeric parameter values using destination type bit-size to reject overflows.
huma_test.go Add coverage ensuring overflow inputs are rejected (and handler is not called).

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

Comment thread huma_test.go Outdated
Comment thread huma.go
leonklingele and others added 2 commits August 8, 2026 15:53
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

2 participants