Skip to content

Commit

Permalink
MDEV-11881 Empty coordinates must be rejected in GeoJSON objects.
Browse files Browse the repository at this point in the history
        Check for the empty 'coordinates' array.
  • Loading branch information
Alexey Botchkov committed Nov 14, 2017
1 parent 5632652 commit 2418493
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
15 changes: 15 additions & 0 deletions mysql-test/r/gis-json.result
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ ST_AsGeoJSON(ST_GeomFromText("POINT(10 11)"), 100, 1)
SELECT ST_AsGeoJSON(ST_GeomFromText("POINT(10 11)"), 100, 5);
ST_AsGeoJSON(ST_GeomFromText("POINT(10 11)"), 100, 5)
{"bbox": [10, 11, 10, 11], "type": "Point", "coordinates": [10, 11]}
SELECT st_astext(st_geomfromgeojson('{"type": "MultiLineString","coordinates": []}')) as a;
a
NULL
Warnings:
Warning 4076 Incorrect GeoJSON format - empty 'coordinates' array.
SELECT st_astext(st_geomfromgeojson('{"type": "Polygon","coordinates": []}')) as a;
a
NULL
Warnings:
Warning 4076 Incorrect GeoJSON format - empty 'coordinates' array.
SELECT st_astext(st_geomfromgeojson('{"type": "MultiPolygon","coordinates": []}')) as a;
a
NULL
Warnings:
Warning 4076 Incorrect GeoJSON format - empty 'coordinates' array.
#
# End of 10.2 tests
#
4 changes: 4 additions & 0 deletions mysql-test/t/gis-json.test
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ SELECT ST_AsGeoJSON(ST_GeomFromText('POINT(5.363 7.266)'),10);
SELECT ST_AsGeoJSON(ST_GeomFromText("POINT(10 11)"), 100, 1);
SELECT ST_AsGeoJSON(ST_GeomFromText("POINT(10 11)"), 100, 5);

SELECT st_astext(st_geomfromgeojson('{"type": "MultiLineString","coordinates": []}')) as a;
SELECT st_astext(st_geomfromgeojson('{"type": "Polygon","coordinates": []}')) as a;
SELECT st_astext(st_geomfromgeojson('{"type": "MultiPolygon","coordinates": []}')) as a;

--echo #
--echo # End of 10.2 tests
--echo #
3 changes: 3 additions & 0 deletions sql/item_geofunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ String *Item_func_geometry_from_json::val_str(String *str)
case Geometry::GEOJ_TOO_FEW_POINTS:
code= ER_GEOJSON_TOO_FEW_POINTS;
break;
case Geometry::GEOJ_EMPTY_COORDINATES:
code= ER_GEOJSON_EMPTY_COORDINATES;
break;
case Geometry::GEOJ_POLYGON_NOT_CLOSED:
code= ER_GEOJSON_NOT_CLOSED;
break;
Expand Down
3 changes: 3 additions & 0 deletions sql/share/errmsg-utf8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7746,3 +7746,6 @@ ER_SUM_FUNC_WITH_WINDOW_FUNC_AS_ARG

ER_NET_OK_PACKET_TOO_LARGE
eng "OK packet too large"

ER_GEOJSON_EMPTY_COORDINATES
eng "Incorrect GeoJSON format - empty 'coordinates' array."
35 changes: 34 additions & 1 deletion sql/spatial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ bool Gis_line_string::init_from_json(json_engine_t *je, bool er_on_3D,
}
if (n_points < 1)
{
je->s.error= GEOJ_TOO_FEW_POINTS;
je->s.error= Geometry::GEOJ_TOO_FEW_POINTS;
return TRUE;
}
wkb->write_at_position(np_pos, n_points);
Expand Down Expand Up @@ -1440,6 +1440,15 @@ bool Gis_polygon::init_from_json(json_engine_t *je, bool er_on_3D, String *wkb)
}
n_linear_rings++;
}

if (je->s.error)
return TRUE;

if (n_linear_rings == 0)
{
je->s.error= Geometry::GEOJ_EMPTY_COORDINATES;
return TRUE;
}
wkb->write_at_position(lr_pos, n_linear_rings);
return FALSE;
}
Expand Down Expand Up @@ -1945,6 +1954,14 @@ bool Gis_multi_point::init_from_json(json_engine_t *je, bool er_on_3D,
n_points++;
}

if (je->s.error)
return TRUE;
if (n_points == 0)
{
je->s.error= Geometry::GEOJ_EMPTY_COORDINATES;
return TRUE;
}

wkb->write_at_position(np_pos, n_points);
return FALSE;
}
Expand Down Expand Up @@ -2214,6 +2231,15 @@ bool Gis_multi_line_string::init_from_json(json_engine_t *je, bool er_on_3D,

n_line_strings++;
}
if (je->s.error)
return TRUE;

if (n_line_strings == 0)
{
je->s.error= Geometry::GEOJ_EMPTY_COORDINATES;
return TRUE;
}

wkb->write_at_position(ls_pos, n_line_strings);
return FALSE;
}
Expand Down Expand Up @@ -2603,6 +2629,13 @@ bool Gis_multi_polygon::init_from_json(json_engine_t *je, bool er_on_3D,

n_polygons++;
}
if (je->s.error)
return TRUE;
if (n_polygons == 0)
{
je->s.error= Geometry::GEOJ_EMPTY_COORDINATES;
return TRUE;
}
wkb->write_at_position(np_pos, n_polygons);
return FALSE;
}
Expand Down
1 change: 1 addition & 0 deletions sql/spatial.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class Geometry
GEOJ_TOO_FEW_POINTS= 2,
GEOJ_POLYGON_NOT_CLOSED= 3,
GEOJ_DIMENSION_NOT_SUPPORTED= 4,
GEOJ_EMPTY_COORDINATES= 5,
};


Expand Down

0 comments on commit 2418493

Please sign in to comment.