summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2021-06-28 11:52:00 +0400
committerAlexey Botchkov <holyfoot@askmonty.org>2021-06-28 11:53:33 +0400
commit8147d2e6183a1a4a4f3db2884966f5da2d17678c (patch)
treee24f1137da498939a5c818f10a2086a907dc95ee
parent4e4f742ed7987ee52a34618d2ea3731e5e198ed8 (diff)
downloadmariadb-git-8147d2e6183a1a4a4f3db2884966f5da2d17678c.tar.gz
MDEV-25461 Assertion `je->state == JST_KEY' failed in Geometry::create_from_json.
Handle invalid GEOJSON-s in Geometry::create_from_json().
-rw-r--r--mysql-test/r/gis-json.result10
-rw-r--r--mysql-test/t/gis-json.test7
-rw-r--r--sql/spatial.cc6
3 files changed, 23 insertions, 0 deletions
diff --git a/mysql-test/r/gis-json.result b/mysql-test/r/gis-json.result
index e52a7c809c6..ace9e9e9ae2 100644
--- a/mysql-test/r/gis-json.result
+++ b/mysql-test/r/gis-json.result
@@ -107,6 +107,16 @@ Warning 4076 Incorrect GeoJSON format - empty 'coordinates' array.
SELECT ST_GEOMFROMGEOJSON("{ \"type\": \"Feature\", \"geometry\": [10, 20] }");
ST_GEOMFROMGEOJSON("{ \"type\": \"Feature\", \"geometry\": [10, 20] }")
NULL
+SELECT ST_ASTEXT (ST_GEOMFROMGEOJSON ('{ "type": "GEOMETRYCOLLECTION", "coordinates": [102.0, 0.0]}'));
+ST_ASTEXT (ST_GEOMFROMGEOJSON ('{ "type": "GEOMETRYCOLLECTION", "coordinates": [102.0, 0.0]}'))
+NULL
+Warnings:
+Warning 4048 Incorrect GeoJSON format specified for st_geomfromgeojson function.
+SELECT ST_ASTEXT(ST_GEOMFROMGEOJSON('{"type": ["POINT"], "coINates": [0,0] }'));
+ST_ASTEXT(ST_GEOMFROMGEOJSON('{"type": ["POINT"], "coINates": [0,0] }'))
+NULL
+Warnings:
+Warning 4048 Incorrect GeoJSON format specified for st_geomfromgeojson function.
#
# End of 10.2 tests
#
diff --git a/mysql-test/t/gis-json.test b/mysql-test/t/gis-json.test
index a97e9411e5c..ff6298c50a6 100644
--- a/mysql-test/t/gis-json.test
+++ b/mysql-test/t/gis-json.test
@@ -46,6 +46,13 @@ SELECT st_astext(st_geomfromgeojson('{"type": "MultiPolygon","coordinates": []}'
SELECT ST_GEOMFROMGEOJSON("{ \"type\": \"Feature\", \"geometry\": [10, 20] }");
+#
+# MDEV-25461 Assertion `je->state == JST_KEY' failed in Geometry::create_from_json.
+#
+
+SELECT ST_ASTEXT (ST_GEOMFROMGEOJSON ('{ "type": "GEOMETRYCOLLECTION", "coordinates": [102.0, 0.0]}'));
+
+SELECT ST_ASTEXT(ST_GEOMFROMGEOJSON('{"type": ["POINT"], "coINates": [0,0] }'));
--echo #
--echo # End of 10.2 tests
--echo #
diff --git a/sql/spatial.cc b/sql/spatial.cc
index 7bb3ecff948..8bd9acef18f 100644
--- a/sql/spatial.cc
+++ b/sql/spatial.cc
@@ -539,7 +539,11 @@ Geometry *Geometry::create_from_json(Geometry_buffer *buffer,
goto handle_geometry_key;
feature_type_found= 1;
}
+ else /* can't understand the type. */
+ break;
}
+ else /* The "type" value can only be string. */
+ break;
}
else if (key_len == coord_keyname_len &&
memcmp(key_buf, coord_keyname, coord_keyname_len) == 0)
@@ -556,6 +560,8 @@ Geometry *Geometry::create_from_json(Geometry_buffer *buffer,
coord_start= je->value_begin;
if (ci && ci != &geometrycollection_class)
goto create_geom;
+ if (json_skip_level(je))
+ goto err_return;
}
}
else if (key_len == geometries_keyname_len &&