Repository navigation
Reject out-of-domain coordinates in the h3 polygon functions - #116225
alexey-milovidov wants to merge 3 commits into
Conversation
`h3PolygonToCellsWithContainment` could spin in an effectively unbounded loop inside the H3 library when a vertex of the polygon was outside the domain latitude and longitude are defined on. The loop is inside a single `maxPolygonToCellsSizeExperimental` call, so it observes neither `max_execution_time` nor `KILL QUERY`: the query in the report below had `is_cancelled = 1` and had been running for 500 seconds when the hung check gave up. H3 derives the part of the grid its polyfill has to walk from the polygon's bounding box, and it reduces the resolution it walks at until that box holds about ten cells. With a latitude of `1e20` degrees the rough area the heuristic computes comes out negative, no reduction happens, and the walk covers every cell of the target resolution - about 4.9e9 cells at resolution 9. H3 itself only rejects coordinates that are not finite, so check the domain before calling into it: longitude in `[-180, 180]` and latitude in `[-90, 90]` degrees, which is H3's own `VALID_RANGE_BBOX`. Values outside it never produced anything useful anyway - a polygon at longitude 200 returns an empty array today, because H3 does not wrap longitudes. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=2797514bd2d8b632984538bb9989356995b8a7c8&name_0=MasterCI&name_1=Stress%20test%20%28amd_tsan%29 Closes: #116195
|
Workflow [PR], commit [1f8b5f0] Summary: ❌
AI ReviewSummaryThis PR adds an explicit longitude/latitude domain check before the two H3 polygon functions call into H3's polyfill path, so inputs outside Final Verdict✅ No new review findings. LLVM Coverage ReportMeasured on commit 1f8b5f0.
Changed lines: Changed C/C++ lines covered: 43/43 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units36 translation units recompiled, 100 s compile time in total, 36 of them have a recent master baseline. |
Algunenano
left a comment
There was a problem hiding this comment.
A more complete implementation here: #116335 It both rejects out of domain coordinates and implements better timeout checks
…ut-of-domain-coordinates
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116225&sha=4a99f82e7b2fe4628b8224e6db30aca5c55a34f3&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29 and provide a fix in a separate PR. Two tests failed there, both unrelated to this PR (it only touches the |
|
Both failures on that run are the same macOS runner disk exhaustion, not two defects: Over the last 21 days of The fix is already open: #113605, since 2026-08-06. On master It is mergeable and waiting on review from the runner owner: @ Algunenano asked @ leshikus to look on 2026-08-06, and I posted the per-job evidence the same day. There is no open issue for either test. |
…ut-of-domain-coordinates
|
🕵 Merged
@groeneai, investigate the second one: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116225&sha=7bf4ed2b2ff741cbdd47defab99250eec27d8fa5&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 and provide a fix in a separate PR. If a fix is already in progress, link it here. |
|
Investigated. That red is not the The single fatal in that run is on the pre-upgrade server (
Fixed on It still fires here because the guard is on One caveat on the reported name. |
|
Closing in favour of #116335, which includes this fix and several others |
h3PolygonToCellsWithContainmentcould spin in an effectively unbounded loop inside the H3 library when a vertex of the polygon was outside the domain latitude and longitude are defined on. The loop runs inside a singlemaxPolygonToCellsSizeExperimentalcall, so it observes neithermax_execution_timenorKILL QUERY- the query below hadis_cancelled = 1and had been running for 500 seconds when the stress-test hung check gave up:(The AST fuzzer produced it from
04910_h3_array_building_no_quadratic_realloc.)H3 derives the part of the grid its polyfill has to walk from the polygon's bounding box, and reduces the resolution it walks at until that box holds about ten cells. With a latitude of
1e20degrees the rough area that heuristic computes comes out negative, no reduction happens, and the walk covers every cell of the target resolution - about 4.9e9 cells at resolution 9, measured at roughly 250k cells per second.H3 itself only rejects coordinates that are not finite, so this checks the domain before calling into it: longitude in
[-180, 180]and latitude in[-90, 90]degrees, which is H3's ownVALID_RANGE_BBOX. Coordinates outside that range never produced anything useful anyway - H3 does not wrap longitudes, so a polygon at longitude 200 returns an empty array today. Bothh3PolygonToCellsandh3PolygonToCellsWithContainmentnow throwARGUMENT_OUT_OF_BOUND, for the holes of a polygon as well as for its exterior ring.Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=2797514bd2d8b632984538bb9989356995b8a7c8&name_0=MasterCI&name_1=Stress%20test%20%28amd_tsan%29
Closes: #116195
Related: #115893
Related: #112203
One thing this does not fix, measured while investigating: a polygon whose bounding box is degenerate with perfectly valid coordinates - all vertices on one meridian, or a box spanning exactly
[-180, 180]- also makes the area heuristic yield0and defeats the resolution reduction. The walk is then along a one-dimensional strip rather than over the whole grid, so it is finite: 30 seconds in a release build for a 20-degree meridian at resolution 15. That needs a change in the H3 resolution heuristic itself, which is why it is left out here.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Functions
h3PolygonToCellsandh3PolygonToCellsWithContainmentnow reject coordinates outside their domain (longitude in[-180, 180], latitude in[-90, 90]degrees) instead of running for an unbounded time that could not be interrupted bymax_execution_timeorKILL QUERY.Workflow [PR]
Sync PR [sync-upstream/pr/116225]