Repository navigation
fix: enforce geometry subtype validation at INSERT/UPDATE bind time - #24353
Conversation
…atrixorigin#24350) Port cast_geometry_to_subtype runtime function from main to 3.0-dev so that INSERT/UPDATE operations validate the WKT subtype and SRID against the column declaration, rejecting mismatches at plan time. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
1. bind_insert.go:173 and build_constraint_util.go:717 now route geometry columns through funcCastForGeometryType instead of plain forceCastExpr, closing the ON DUPLICATE KEY UPDATE loophole. 2. Move geometry cast check before isSameColumnType() in makePlan2CastExpr so that two T_geometry types with different Enumvalues (subtype metadata) still get validated. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1. ODKU ON UPDATE path now validates geometry via funcCastForGeometryType. 2. All DEFAULT value paths (getDefaultExpr + *tree.DefaultVal) in bind_insert.go and build_constraint_util.go now pass geometry columns through subtype validation. 3. Expand test suite: all geometry subtypes, SRID matching/mismatch, EMPTY geometries, malformed structures, null propagation, and GEOMETRY(...) wrapper bypass. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add tests for all type switch branches in maxPointsInGeometryLimit, point count exceeded path, multipoint/multilinestring/multipolygon count helpers, generic geometry content validation, collection nesting depth limit, encode/decode payload helpers, and split/parse utilities. All functions in func_geometry.go now exceed 75% coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Cover funcCastForGeometryType, isGeometryNullLiteralExpr, isGeometryPlanType, geometrySubtypeName, and normalizeGeometrySubtype to satisfy CI coverage check on new lines. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
LGTM. Clean port of geometry subtype/SRID validation from main to 3.0-dev.
Design
funcCastForGeometryType wraps geometry column expressions with a cast_geometry_to_subtype(metadata, value) runtime function at bind time. The metadata string carries "POINT;SRID=4326" (subtype + SRID), and the runtime function validates:
- WKT type name matches column subtype (POINT/LINESTRING/POLYGON/etc.)
- SRID matches column SRID (with assignment semantics when value has no SRID)
- WKT structural validity (parenthesis balance, coordinate pair count, ring closure)
- Finite coordinates (rejects NaN/Inf)
- Point count cap via
max_points_in_geometrysession variable
Correctness verified
- All INSERT/UPDATE bind paths covered: 5 call sites in
bind_insert.go, 4 inbind_update.go/build_update.go, 6 inbuild_constraint_util.go, plusmake.go:577for general cast wrapping. ON DUPLICATE KEY UPDATE path covered (commitbdd8ab11). - Short-circuits correct:
T_anytype and NULL literal expressions skip validation (line 84-87). Same-type same-metadata passes through without re-validation (line 89-91). - Security:
splitTopLevelGeometryItemsStricttracks parenthesis depth, rejects unbalanced/empty items.maxGeometryCollectionNestingDepth=64caps recursion depth.maxPointsInGeometrydefaults to 65536. No injection risk — the metadata string is always from the catalogEnumvaluesfield. GEOMETRYcolumn (base type) correctly accepts all subtypes at line 63:columnSubtype != "GEOMETRY"means a GEOMETRY column with no explicit subtype doesn't reject any valid geometry.
Test coverage
func_geometry_test.go(759 lines): 11 test functions covering subtype match/reject, SRID match/mismatch/assign, malformed WKT, NULL handling, all geometry types (MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION), point count limits, and helper functions.mysql_special_types_test.go(152 lines): coversfuncCastForGeometryType,isGeometryNullLiteralExpr, type predicates, and subtype normalization.
Minor observation (not blocking)
validateFiniteCoordinatesInGeometryText tokenizes the entire WKT and attempts ParseFloat on every token including type names ("POINT", "LINESTRING"). Non-numeric tokens fail ParseFloat but the function only rejects when err == nil && (IsNaN || IsInf) — so type-name tokens are silently skipped. This is functionally correct but slightly wasteful. A prefix check for digit/sign/dot before ParseFloat would avoid the failed parse attempts. Not blocking — it's validation-path, not hot-loop.
CI still running (SCA + checks passed). Merge after green.
Merge Queue Status
This pull request spent 1 hour 8 seconds in the queue, including 59 minutes 38 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #24350
What this PR does / why we need it:
Ports the
cast_geometry_to_subtyperuntime function frommainto3.0-devso that INSERT/UPDATE operations validate the WKT geometry subtype and SRID against the column declaration. Previously on3.0-dev, a column declared asPOINTcould silently accept aLINESTRINGvalue.Changes:
CAST_GEOMETRY_TO_SUBTYPEfunction ID and built-in overloadCastGeometryToSubtyperuntime function with full WKT structure validationfuncCastForGeometryTypeplanner function that wraps geometry expressions with subtype/SRID validationT_geometrysupport to the function test framework🤖 Generated with Claude Code