Skip to content

fix(geo): reject out-of-range geodetic coordinates - #28815

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-28191-geodetic-ranges-20260913
Sep 13, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-28191-geodetic-ranges-20260913

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • API-change
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #28191

What this PR does / why we need it:

SRID-4326 ST_Distance, ST_Length, and ST_Area previously passed finite out-of-range longitude/latitude values to S2, which normalizes them and can return plausible but incorrect measurements. Add one allocation-free coordinate validator and invoke it at the geodetic measurement boundary. Distance validates both operands before containment/zero-distance shortcuts, so an invalid later vertex cannot be hidden by an earlier match.

The effective SRID determines validation: typed or explicit SRID 4326 enforces finite longitude [-180,180] and latitude [-90,90]; SRID 0 remains Cartesian, including explicit SRID-0 overrides on values typed as 4326. Constructors/storage and the separate ST_DISTANCE_SPHERE contract are unchanged. GEOGRAPHY and GEOGRAPHY32 use the same guard.

Risks and performance

  • Each effective SRID-4326 measurement adds one O(n) coordinate scan (O(n+m) for distance); kernel complexity is unchanged. On Apple M4, a temporary microbenchmark measured approximately +1% for point distance, +5.3% for a 4096-coordinate line, and +2% for a 4096-vertex polygon, with zero additional allocations. These measurements are local directional evidence, not a production workload benchmark.
  • The numeric-only geo.LengthMeters, geo.AreaSquareMeters, and geo.DistanceMeters APIs retain their signatures and cannot return validation errors. Their precondition is now documented; all in-repository production call sites either validate here or use ST_DISTANCE_SPHERE's separate Point/MultiPoint validator.
  • Out-of-range geometry can still be constructed/stored and used under SRID 0; it is rejected when measured using effective SRID 4326. This preserves explicit-SRID override behavior.

Validation

  • Verified the four issue reproducers fail on the unchanged base (67a9a4b130388956971888a67fc626784deade48) because each previously returned success; the same evaluator regressions pass with the fix.
  • GOWORK=off go test -mod=readonly -count=1 -timeout=180s ./pkg/geo — PASS.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m ./pkg/sql/plan/function — PASS.
  • GOWORK=off go vet -mod=readonly ./pkg/geo ./pkg/sql/plan/function — PASS.
  • golangci-lint run --config .golangci.yml --new-from-rev=67a9a4b130388956971888a67fc626784deade48 ./pkg/geo ./pkg/sql/plan/function — PASS, 0 issues.
  • test/distributed/cases/geo/geo_geodetic.sql/.result now covers invalid constants, explicit/default SRID controls, GEOGRAPHY/GEOGRAPHY32 columns, inclusive boundaries, and prepared-query valid → invalid → valid reuse. The BVT was not run against a local service; its result is pending the PR's BVT CI.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

GPT-6 medium deep review at current head 9f22d4de345e5b5c523f3c9ab085d1ea64061cd7: no verified blocking finding.

The validator covers all supported geometry shapes and members, rejects non-finite/out-of-range longitude and latitude, permits inclusive WGS 84 bounds, skips empty points, and bounds nested collections. Both ST_Distance operands are validated before distance/containment shortcuts; ST_Length and ST_Area validate before their numeric kernels. Effective-SRID dispatch keeps SRID 0 Cartesian behavior unchanged, and both geometry precisions use the guarded path.

Racing-UT review: the new work is a linear coordinate scan confined to SRID 4326 geodetic measurements; it adds no shared state, lock, goroutine, or allocation on the common path. Tests reuse lightweight evaluator fixtures and add no cluster, sleeps, retries, or large workloads. Exact-head CI run 34768265065 passed, including Ubuntu UT with the function package in the race-enabled stage and the extended geodetic BVT. No material racing-UT time increase is indicated; no base/head full-suite duration delta was measured.

@XuPeng-SH
XuPeng-SH merged commit 3698ade into matrixorigin:main Sep 13, 2026
17 of 20 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/issue-28191-geodetic-ranges-20260913 branch September 13, 2026 17:34
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [x] BUG
- [ ] API-change
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28191

## What this PR does / why we need it:

SRID-4326 `ST_Distance`, `ST_Length`, and `ST_Area` previously passed
finite out-of-range longitude/latitude values to S2, which normalizes
them and can return plausible but incorrect measurements. Add one
allocation-free coordinate validator and invoke it at the geodetic
measurement boundary. Distance validates both operands before
containment/zero-distance shortcuts, so an invalid later vertex cannot
be hidden by an earlier match.

The effective SRID determines validation: typed or explicit SRID 4326
enforces finite longitude `[-180,180]` and latitude `[-90,90]`; SRID 0
remains Cartesian, including explicit SRID-0 overrides on values typed
as 4326. Constructors/storage and the separate `ST_DISTANCE_SPHERE`
contract are unchanged. `GEOGRAPHY` and `GEOGRAPHY32` use the same
guard.

### Risks and performance

- Each effective SRID-4326 measurement adds one O(n) coordinate scan
(O(n+m) for distance); kernel complexity is unchanged. On Apple M4, a
temporary microbenchmark measured approximately +1% for point distance,
+5.3% for a 4096-coordinate line, and +2% for a 4096-vertex polygon,
with zero additional allocations. These measurements are local
directional evidence, not a production workload benchmark.
- The numeric-only `geo.LengthMeters`, `geo.AreaSquareMeters`, and
`geo.DistanceMeters` APIs retain their signatures and cannot return
validation errors. Their precondition is now documented; all
in-repository production call sites either validate here or use
`ST_DISTANCE_SPHERE`'s separate Point/MultiPoint validator.
- Out-of-range geometry can still be constructed/stored and used under
SRID 0; it is rejected when measured using effective SRID 4326. This
preserves explicit-SRID override behavior.

### Validation

- Verified the four issue reproducers fail on the unchanged base
(`67a9a4b130388956971888a67fc626784deade48`) because each previously
returned success; the same evaluator regressions pass with the fix.
- `GOWORK=off go test -mod=readonly -count=1 -timeout=180s ./pkg/geo` —
PASS.
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m
./pkg/sql/plan/function` — PASS.
- `GOWORK=off go vet -mod=readonly ./pkg/geo ./pkg/sql/plan/function` —
PASS.
- `golangci-lint run --config .golangci.yml
--new-from-rev=67a9a4b130388956971888a67fc626784deade48 ./pkg/geo
./pkg/sql/plan/function` — PASS, 0 issues.
- `test/distributed/cases/geo/geo_geodetic.sql/.result` now covers
invalid constants, explicit/default SRID controls,
`GEOGRAPHY`/`GEOGRAPHY32` columns, inclusive boundaries, and
prepared-query valid → invalid → valid reuse. The BVT was not run
against a local service; its result is pending the PR's BVT CI.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [x] BUG
- [ ] API-change
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28191

## What this PR does / why we need it:

SRID-4326 `ST_Distance`, `ST_Length`, and `ST_Area` previously passed
finite out-of-range longitude/latitude values to S2, which normalizes
them and can return plausible but incorrect measurements. Add one
allocation-free coordinate validator and invoke it at the geodetic
measurement boundary. Distance validates both operands before
containment/zero-distance shortcuts, so an invalid later vertex cannot
be hidden by an earlier match.

The effective SRID determines validation: typed or explicit SRID 4326
enforces finite longitude `[-180,180]` and latitude `[-90,90]`; SRID 0
remains Cartesian, including explicit SRID-0 overrides on values typed
as 4326. Constructors/storage and the separate `ST_DISTANCE_SPHERE`
contract are unchanged. `GEOGRAPHY` and `GEOGRAPHY32` use the same
guard.

### Risks and performance

- Each effective SRID-4326 measurement adds one O(n) coordinate scan
(O(n+m) for distance); kernel complexity is unchanged. On Apple M4, a
temporary microbenchmark measured approximately +1% for point distance,
+5.3% for a 4096-coordinate line, and +2% for a 4096-vertex polygon,
with zero additional allocations. These measurements are local
directional evidence, not a production workload benchmark.
- The numeric-only `geo.LengthMeters`, `geo.AreaSquareMeters`, and
`geo.DistanceMeters` APIs retain their signatures and cannot return
validation errors. Their precondition is now documented; all
in-repository production call sites either validate here or use
`ST_DISTANCE_SPHERE`'s separate Point/MultiPoint validator.
- Out-of-range geometry can still be constructed/stored and used under
SRID 0; it is rejected when measured using effective SRID 4326. This
preserves explicit-SRID override behavior.

### Validation

- Verified the four issue reproducers fail on the unchanged base
(`67a9a4b130388956971888a67fc626784deade48`) because each previously
returned success; the same evaluator regressions pass with the fix.
- `GOWORK=off go test -mod=readonly -count=1 -timeout=180s ./pkg/geo` —
PASS.
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m
./pkg/sql/plan/function` — PASS.
- `GOWORK=off go vet -mod=readonly ./pkg/geo ./pkg/sql/plan/function` —
PASS.
- `golangci-lint run --config .golangci.yml
--new-from-rev=67a9a4b130388956971888a67fc626784deade48 ./pkg/geo
./pkg/sql/plan/function` — PASS, 0 issues.
- `test/distributed/cases/geo/geo_geodetic.sql/.result` now covers
invalid constants, explicit/default SRID controls,
`GEOGRAPHY`/`GEOGRAPHY32` columns, inclusive boundaries, and
prepared-query valid → invalid → valid reuse. The BVT was not run
against a local service; its result is pending the PR's BVT CI.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [x] BUG
- [ ] API-change
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28191

## What this PR does / why we need it:

SRID-4326 `ST_Distance`, `ST_Length`, and `ST_Area` previously passed
finite out-of-range longitude/latitude values to S2, which normalizes
them and can return plausible but incorrect measurements. Add one
allocation-free coordinate validator and invoke it at the geodetic
measurement boundary. Distance validates both operands before
containment/zero-distance shortcuts, so an invalid later vertex cannot
be hidden by an earlier match.

The effective SRID determines validation: typed or explicit SRID 4326
enforces finite longitude `[-180,180]` and latitude `[-90,90]`; SRID 0
remains Cartesian, including explicit SRID-0 overrides on values typed
as 4326. Constructors/storage and the separate `ST_DISTANCE_SPHERE`
contract are unchanged. `GEOGRAPHY` and `GEOGRAPHY32` use the same
guard.

### Risks and performance

- Each effective SRID-4326 measurement adds one O(n) coordinate scan
(O(n+m) for distance); kernel complexity is unchanged. On Apple M4, a
temporary microbenchmark measured approximately +1% for point distance,
+5.3% for a 4096-coordinate line, and +2% for a 4096-vertex polygon,
with zero additional allocations. These measurements are local
directional evidence, not a production workload benchmark.
- The numeric-only `geo.LengthMeters`, `geo.AreaSquareMeters`, and
`geo.DistanceMeters` APIs retain their signatures and cannot return
validation errors. Their precondition is now documented; all
in-repository production call sites either validate here or use
`ST_DISTANCE_SPHERE`'s separate Point/MultiPoint validator.
- Out-of-range geometry can still be constructed/stored and used under
SRID 0; it is rejected when measured using effective SRID 4326. This
preserves explicit-SRID override behavior.

### Validation

- Verified the four issue reproducers fail on the unchanged base
(`67a9a4b130388956971888a67fc626784deade48`) because each previously
returned success; the same evaluator regressions pass with the fix.
- `GOWORK=off go test -mod=readonly -count=1 -timeout=180s ./pkg/geo` —
PASS.
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m
./pkg/sql/plan/function` — PASS.
- `GOWORK=off go vet -mod=readonly ./pkg/geo ./pkg/sql/plan/function` —
PASS.
- `golangci-lint run --config .golangci.yml
--new-from-rev=67a9a4b130388956971888a67fc626784deade48 ./pkg/geo
./pkg/sql/plan/function` — PASS, 0 issues.
- `test/distributed/cases/geo/geo_geodetic.sql/.result` now covers
invalid constants, explicit/default SRID controls,
`GEOGRAPHY`/`GEOGRAPHY32` columns, inclusive boundaries, and
prepared-query valid → invalid → valid reuse. The BVT was not run
against a local service; its result is pending the PR's BVT CI.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SRID 4326 measurements accept out-of-range longitude and latitude

3 participants