[MDEV-11881] Empty coordinates must be rejected in GeoJSON objects Created: 2017-01-23  Updated: 2017-11-14  Resolved: 2017-11-14

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 10.2
Fix Version/s: 10.2.11

Type: Bug Priority: Major
Reporter: Andrii Nikitin (Inactive) Assignee: Alexey Botchkov
Resolution: Fixed Votes: 0
Labels: None

Sprint: 10.2.11

 Description   

MariaDB [(none)]> SELECT st_astext(st_geomfromgeojson('
    '> {
    '>     "type": "MultiLineString",
    '>     "coordinates": [
    '>     ]
    '> }')) as a;
+------------------+
| a                |
+------------------+
| MULTILINESTRING) |
+------------------+
1 row in set (0.00 sec)
 
MariaDB [(none)]>
MariaDB [(none)]> SELECT st_astext(st_geomfromgeojson('
    '> {
    '>     "type": "Polygon",
    '>     "coordinates": [
    '>     ]
    '> }')) as a;
+----------+
| a        |
+----------+
| POLYGON) |
+----------+
1 row in set (0.00 sec)
 
MariaDB [(none)]>
MariaDB [(none)]> SELECT st_astext(st_geomfromgeojson('
    '> {
    '>     "type": "MultiPolygon",
    '>     "coordinates": [
    '>     ]
    '> }')) as a;
+---------------+
| a             |
+---------------+
| MULTIPOLYGON) |
+---------------+
1 row in set (0.00 sec)

These objects are valid in json, but invalid in geojson , so must be handled accordingly.



 Comments   
Comment by Andrii Nikitin (Inactive) [ 2017-01-23 ]

According to the spec http://geojson.org/geojson-spec.html empty array is allowed, so this may be bug in st_astext() , because formatting of doesn't look correct

On the other hand Point type must be rejected when it is not complete:

The "coordinates" member of a geometry object is composed of one position (in the case of a Point geometry), an array of positions (LineString or MultiPoint geometries), an array of arrays of positions (Polygons, MultiLineStrings), or a multidimensional array of positions (MultiPolygon). A position is represented by an array of numbers. There must be at least two elements, and may be more.

MariaDB [test]> select st_astext(st_geomfromgeojson('{"type": "Point","coordinates": []}')), st_astext(st_geomfromgeojson('{"type": "Point","coordinates": [0]}'));
+----------------------------------------------------------------------+-----------------------------------------------------------------------+
| st_astext(st_geomfromgeojson('{"type": "Point","coordinates": []}')) | st_astext(st_geomfromgeojson('{"type": "Point","coordinates": [0]}')) |
+----------------------------------------------------------------------+-----------------------------------------------------------------------+
| POINT(-9.255963134931783e61 -9.255963134931783e61)                   | POINT(0 -9.255963134931783e61)                                        |
+----------------------------------------------------------------------+-----------------------------------------------------------------------+

And again - behavior is inconsistent with st_geomfromtext(), (which cannot accept empty array) and MySQL 5.7, which throws an error to all these cases,
So let me know if this bug should be split into two (e.g. one for Point and one for st_astext() or if we just reject such inputs )

Comment by Andrii Nikitin (Inactive) [ 2017-01-23 ]

Another example of invalid string accepted for linestring:

MariaDB [test]> select astext(st_geomfromgeojson('{"type": "linestring","coordinates": [ [0] [0] [0] ]}'));
+-------------------------------------------------------------------------------------+
| astext(st_geomfromgeojson('{"type": "linestring","coordinates": [ [0] [0] [0] ]}')) |
+-------------------------------------------------------------------------------------+
| LINESTRING(0 -9.255963134931783e61)                                                 |
+-------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
 
MariaDB [test]> select astext(st_geomfromgeojson('{"type": "linestring","coordinates": [ [0] [0,1] [0,1] ]}'));
+-----------------------------------------------------------------------------------------+
| astext(st_geomfromgeojson('{"type": "linestring","coordinates": [ [0] [0,1] [0,1] ]}')) |
+-----------------------------------------------------------------------------------------+
| LINESTRING(0 -9.255963134931783e61)                                                     |
+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
 
MariaDB [test]> select astext(st_geomfromgeojson('{"type": "linestring","coordinates": [ [0,1] [0,1] [0,1] ]}'));
+-------------------------------------------------------------------------------------------+
| astext(st_geomfromgeojson('{"type": "linestring","coordinates": [ [0,1] [0,1] [0,1] ]}')) |
+-------------------------------------------------------------------------------------------+
| LINESTRING(0 1)                                                                           |
+-------------------------------------------------------------------------------------------+

Problem is both that invalid json is accepted (comma is missing) and that linestring requires at least two (valid) positions (i.e. "points") according to mentioned spec

For type "LineString", the "coordinates" member must be an array of two or more positions.

Comment by Alexey Botchkov [ 2017-11-14 ]

http://lists.askmonty.org/pipermail/commits/2017-November/011653.html

Generated at Thu Feb 08 07:53:23 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.