]> granicus.if.org Git - postgis/commitdiff
ST_GeomFromGeoJSON - Malformed GeoJSON causes SIGSEGV in postgres process (#1434)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Sat, 7 Jan 2012 00:29:34 +0000 (00:29 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Sat, 7 Jan 2012 00:29:34 +0000 (00:29 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8690 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_in_geojson.c
regress/tickets.sql
regress/tickets_expected

index 1c20ba4165fcef5c0a59fc46eb6de801536a22f4..bb6cce151d1fe7d43cb39d99973c218ebd0614bf 100644 (file)
@@ -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 ) )
        {
index f39a5a842b7be2d2bd0ec07fdc0a9fe7827661ef..8f5f19fcade0fdbea9fa6153ddfdeac0b7666cd1 100644 (file)
@@ -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;
 
index de8ef7fd06ad755ec1b1fb131e165aaa51ddbfd5..7828c75df9b08155f6fce1706b102f7d48e6e0bf 100644 (file)
@@ -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)