Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-11881

Empty coordinates must be rejected in GeoJSON objects

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.2(EOL)
    • 10.2.11
    • JSON
    • None
    • 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.

      Attachments

        Activity

          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 )

          anikitin Andrii Nikitin (Inactive) added a comment - 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 )

          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.

          anikitin Andrii Nikitin (Inactive) added a comment - 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.
          holyfoot Alexey Botchkov added a comment - http://lists.askmonty.org/pipermail/commits/2017-November/011653.html

          People

            holyfoot Alexey Botchkov
            anikitin Andrii Nikitin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.