fix(backend): validate static-map coordinates before quantization - #13262
Conversation
Parse raw latitude and longitude as floats and enforce [-90, 90] and [-180, 180] bounds before applying 4-decimal quantization. Add unit tests covering coordinate excursions and exact boundary values. Fixes BasedHardware#13249 Failure-Class: none Signed-off-by: Abhi <108084481+Aj2280@users.noreply.github.com> Co-authored-by: PlayerBC <72750390+PlayerBC@users.noreply.github.com>
|
Verified the fix in Everything downstream of the check is unchanged — quantization, de-dup, sorting, and the 50-pin cap behave exactly as before, so the only behavior delta is that genuinely out-of-bounds pins now (correctly) return 400. Test coverage is well targeted: the boundary excursions added to Clean, tight bug fix — nice work, and thanks for linking it to the bounty issue (#13249). by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
kodjima33
left a comment
There was a problem hiding this comment.
Scoped backend bug fix (validate coords before quantization), tests added, CI green, not yet fixed on main.
|
Hi @kodjima33, Thank you so much for merging my PRs (#13262, #13099, #13089, #13084, #13083, #13081, #13080, #13079)! I wanted to politely clarify: are the bounties proposed on these issues real/active, and do these merged fixes qualify for any bounty payout? Support mentioned that because the issues didn't carry the official "Paid Bounty" label, only maintainers can confirm if retroactive bounties apply. Also, I wanted to check if these qualify for the 5+ merged PRs contributor milestone reward (Free DevKit device). Could you please clarify when you have a moment so I understand how bounties work here moving forward? Really appreciate your time, guidance, and help! |
Summary
In
backend/utils/static_map.py::parse_pins, latitude and longitude were previously rounded to_PIN_PRECISION(4 decimal places) before enforcing the[-90, 90]and[-180, 180]coordinate bounds. Because of this premature rounding, out-of-range coordinates that slightly exceed legal boundaries (such as90.00004, 0or0, 180.00004) rounded onto the legal boundary (90.0and180.0) and were erroneously accepted.This PR validates the raw parsed float coordinates against the legal bounds before applying the 4-decimal quantization used for de-duplication and cache keys.
Fixes #13249
Changes
backend/utils/static_map.py:raw_latandraw_lngas floats first.-90 <= raw_lat <= 90and-180 <= raw_lng <= 180before rounding.round(..., _PIN_PRECISION)only to valid coordinates.backend/tests/routers/test_static_map.py:90.00004,0,-90.00004,0,0,180.00004,0,-180.00004) totest_malformed_pins_are_rejected_with_400.test_parse_pins_rejects_out_of_bounds_coordinates_before_quantizationtesting both out-of-bounds rejection and exact boundary validity.Product Invariants Affected
none
Failure-Class
Failure-Class: none
Verification
pytest tests/routers/test_static_map.py(22/22 passed in 0.59s).scripts/backend-python-format --write backend/utils/static_map.py backend/tests/routers/test_static_map.py.