Repository navigation
Reject NaN and Inf in float query parameters - #1490
aaronbrethorst merged 3 commits into
Conversation
strconv.ParseFloat accepts "NaN" and "Inf", so ParseFloatParam and ParseRequiredFloatParam passed them through as valid numbers. NaN then slips past the range checks in ValidateLocationParams, because every comparison with NaN is false, and stops-for-location, routes-for-location and trips-for-location answered lat=NaN (or radius/latSpan/lonSpan=NaN) with a 200 and an empty list instead of a 400. Treat non-finite values like any other unparseable value: add the "Invalid field value" error and return 0. This also covers "Inf" and values that overflow, such as "1e400".
Cover NaN, Inf and an overflowing value (1e400) in ParseFloatParam, and NaN/Inf/-Inf in ParseRequiredFloatParam. All of them used to parse without an error.
With every location parameter set to NaN, parseLocationParams used to return a location and no errors, which is how the location endpoints ended up answering 200.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughFloat parameter parsing now rejects NaN and infinite values, records invalid-value errors, and returns zero. Tests cover optional and required float parsing, including location parameters. ChangesFloat parameter validation
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to Non-finite float query values are rejected, and invalid location requests receive validation errors before route lookup. No actionable merge risk is evident in the supplied changes. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Non-finite location values now receive the existing validation response instead of reaching location processing. No new security exposure was identified, but broader security coverage and client compatibility expectations remain unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
aaronbrethorst
left a comment
There was a problem hiding this comment.
Thanks! This looks good. Rejecting NaN, ±Inf and overflow values in ParseFloatParam/ParseRequiredFloatParam is consistent with how we already return 400 for out-of-range coordinates, and returning 0 alongside the error also fixes the old behavior of handing back +Inf on overflow.



strconv.ParseFloataccepts"NaN"and"Inf", soParseFloatParamtreated them as valid numbers. NaN then passes the range checks inValidateLocationParams, since every comparison with NaN is false:The same happens for
radius,latSpanandlonSpanset toNaN, and inroutes-for-locationandtrips-for-location, which shareparseLocationParams.Change
Both
ParseFloatParamandParseRequiredFloatParamnow treat a non-finite result like any other unparseable value: they add the usualInvalid field value for field "x".error and return 0. That also catchesInfand values that overflow, like1e400.Before,
radius=Infgot through and came back as a 200 withlimitExceeded: trueand no stops. Now it's a 400.Testing
1e400inTestParseFloatParamandTestParseRequiredFloatParam, plus aparseLocationParamscase with every parameter set toNaN. All of them fail onmain.go vet(both tag sets),go fmtandmake testpass. The only exception isTestBuildApplicationWithConfigFile, which downloads a live GTFS feed my sandbox can't reach; it fails onmaintoo.I used Claude to help track this down and write the tests; I reviewed the change and ran everything locally.
Summary by CodeRabbit
NaNand infinite values, returning validation errors instead of producing invalid location results.