From: Paul Ramsey Date: Sat, 7 Jan 2012 00:29:34 +0000 (+0000) Subject: ST_GeomFromGeoJSON - Malformed GeoJSON causes SIGSEGV in postgres process (#1434) X-Git-Tag: 2.0.0alpha1~185 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b47da47ea106b596df972956a25dc93ae1c12e19;p=postgis ST_GeomFromGeoJSON - Malformed GeoJSON causes SIGSEGV in postgres process (#1434) git-svn-id: http://svn.osgeo.org/postgis/trunk@8690 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/lwgeom_in_geojson.c b/postgis/lwgeom_in_geojson.c index 1c20ba416..bb6cce151 100644 --- a/postgis/lwgeom_in_geojson.c +++ b/postgis/lwgeom_in_geojson.c @@ -126,7 +126,9 @@ parse_geojson_point(json_object *geojson, bool *hasz, int *root_srid) POSTGIS_DEBUGF(3, "parse_geojson_point called with root_srid = %d.", *root_srid ); coords = findMemberByName( geojson, "coordinates" ); - + if ( ! coords ) + geojson_lwerror("Unable to find 'coordinates' in GeoJSON string", 4); + pa = ptarray_construct_empty(1, 0, 1); parse_geojson_coord(coords, hasz, pa); @@ -146,6 +148,8 @@ parse_geojson_linestring(json_object *geojson, bool *hasz, int *root_srid) POSTGIS_DEBUG(2, "parse_geojson_linestring called."); points = findMemberByName( geojson, "coordinates" ); + if ( ! points ) + geojson_lwerror("Unable to find 'coordinates' in GeoJSON string", 4); pa = ptarray_construct_empty(1, 0, 1); @@ -176,6 +180,8 @@ parse_geojson_polygon(json_object *geojson, bool *hasz, int *root_srid) int ring = 0; rings = findMemberByName( geojson, "coordinates" ); + if ( ! rings ) + geojson_lwerror("Unable to find 'coordinates' in GeoJSON string", 4); ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*)); @@ -232,6 +238,8 @@ parse_geojson_multipoint(json_object *geojson, bool *hasz, int *root_srid) } poObjPoints = findMemberByName( geojson, "coordinates" ); + if ( ! poObjPoints ) + geojson_lwerror("Unable to find 'coordinates' in GeoJSON string", 4); if( json_type_array == json_object_get_type( poObjPoints ) ) { @@ -270,6 +278,8 @@ parse_geojson_multilinestring(json_object *geojson, bool *hasz, int *root_srid) } poObjLines = findMemberByName( geojson, "coordinates" ); + if ( ! poObjLines ) + geojson_lwerror("Unable to find 'coordinates' in GeoJSON string", 4); if( json_type_array == json_object_get_type( poObjLines ) ) { @@ -317,6 +327,8 @@ parse_geojson_multipolygon(json_object *geojson, bool *hasz, int *root_srid) } poObjPolys = findMemberByName( geojson, "coordinates" ); + if ( ! poObjPolys ) + geojson_lwerror("Unable to find 'coordinates' in GeoJSON string", 4); if( json_type_array == json_object_get_type( poObjPolys ) ) { @@ -389,6 +401,8 @@ parse_geojson_geometrycollection(json_object *geojson, bool *hasz, int *root_sr } poObjGeoms = findMemberByName( geojson, "geometries" ); + if ( ! poObjGeoms ) + geojson_lwerror("Unable to find 'geometries' in GeoJSON string", 4); if( json_type_array == json_object_get_type( poObjGeoms ) ) { diff --git a/regress/tickets.sql b/regress/tickets.sql index f39a5a842..8f5f19fca 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -480,6 +480,12 @@ WITH pts AS ( SELECT 'POINT(0 45)'::geography AS s, 'POINT(45 45)'::geography AS SELECT '#1305.2',abs(ST_Distance(e, ST_Project(s, ST_Distance(s, e), ST_Azimuth(s, e)))) < 0.001 FROM pts; SELECT '#1305.3',ST_Azimuth('POINT(0 45)'::geography, 'POINT(0 45)'::geography) IS NULL; +-- #1434 +select '#1434: Next two errors'; +select '#1434.1',ST_GeomFromGeoJSON('{ "type": "Point", "crashme": [100.0, 0.0] }'); +select '#1434.2',ST_GeomFromGeoJSON('crashme');; + + -- Clean up DELETE FROM spatial_ref_sys; diff --git a/regress/tickets_expected b/regress/tickets_expected index de8ef7fd0..7828c75df 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -149,3 +149,6 @@ ERROR: Geometry type (Polygon) does not match column type (MultiPolygon) #1305.1|POINT(10 10) #1305.2|t #1305.3|t +#1434: Next two errors +ERROR: Unable to find 'coordinates' in GeoJSON string +ERROR: unexpected character (at offset 0)