Skip to content

fix(validation): correct int-width bound in GetIntFromInterface#538

Merged
Phil-Browne merged 1 commit into
mainfrom
esd-1648-conversion-overflow
Jul 13, 2026
Merged

fix(validation): correct int-width bound in GetIntFromInterface#538
Phil-Browne merged 1 commit into
mainfrom
esd-1648-conversion-overflow

Conversation

@Phil-Browne

Copy link
Copy Markdown
Contributor

Extracted from #535 (ESD-1648) as a standalone fix, orthogonal to the prompt/validator-parity work in that PR.

GetIntFromInterface compared a JSON-derived float64 against math.MaxInt directly. float64(math.MaxInt) rounds up to 2^63 only when int is 64 bits, so on platforms where MaxInt fits exactly in a float64 (e.g. 32-bit int, js/wasm) the check wrongly rejected the true max int.

  • Use >= float64(math.MaxInt)+1 as the exclusive upper bound, correct on either int width.
  • Derive the boundary tests from math.MaxInt instead of a hardcoded 2^63 so they stay in range on any platform.

Comparing a float64 against math.MaxInt directly wrongly rejects the true
max int on platforms where MaxInt fits exactly in a float64 (float64(MaxInt)
only rounds up to 2^63 when int is 64 bits). Add 1 to get the correct
exclusive upper bound on either width, and derive the boundary tests from
math.MaxInt instead of a hardcoded 2^63 so they stay in range regardless
of platform int width.
@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.58%. Comparing base (9ba6a3b) to head (7bbcb18).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #538      +/-   ##
==========================================
+ Coverage   78.57%   78.58%   +0.01%     
==========================================
  Files         192      192              
  Lines       18522    18522              
==========================================
+ Hits        14553    14555       +2     
+ Misses       2904     2902       -2     
  Partials     1065     1065              
Files with missing lines Coverage Δ
internal/validation/conversion.go 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Phil-Browne added a commit that referenced this pull request Jul 11, 2026
The GetIntFromInterface int-width bound fix and the interactive
tag-editing empty-value fix are orthogonal to the prompt/validator
parity work here, so they were pulled into their own PRs:

- GetIntFromInterface overflow bound -> #538
- interactive tag-edit empty-value handling -> #539

Restores those six files to the main baseline; this PR now stays
focused on partner-config and prefix-filter validation parity.

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

Fixes a platform-dependent overflow check in internal/validation.GetIntFromInterface when converting JSON-derived float64 values to int, ensuring correct behavior across 32-bit (including js/wasm) and 64-bit int targets.

Changes:

  • Adjusts the float64→int upper-bound validation to use an exclusive bound (v >= float64(math.MaxInt)+1) to avoid float64(math.MaxInt) rounding pitfalls.
  • Updates unit tests to use math.MaxInt-derived boundary values (instead of hardcoded 2^63) for platform portability.

Reviewed changes

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

File Description
internal/validation/conversion.go Updates float64 range validation logic to correctly reject out-of-range values regardless of int width / float64 rounding behavior.
internal/validation/conversion_test.go Extends test coverage around the upper-bound behavior using math.MaxInt-derived values.

Comment thread internal/validation/conversion_test.go

@penzeliz-megaport penzeliz-megaport left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed for correctness; no findings. LGTM.

@Phil-Browne Phil-Browne merged commit 0a2cb6e into main Jul 13, 2026
11 checks passed
@Phil-Browne Phil-Browne deleted the esd-1648-conversion-overflow branch July 13, 2026 13:44
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