]> granicus.if.org Git - postgis/commitdiff
#2619, SIGSEGV in ST_GeomFromGeoJSON with empty list of coordinates
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 26 Mar 2014 09:25:28 +0000 (09:25 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 26 Mar 2014 09:25:28 +0000 (09:25 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@12355 b70326c6-7e19-0410-871a-916f4a2858ee

configure.ac
liblwgeom/lwin_geojson.c
regress/in_geojson.sql
regress/in_geojson_expected

index e317ca514d27b192cb7d9067619454caedbe48dc..66eddd381cde76c5b9527381d471c91076b85efa 100644 (file)
@@ -755,7 +755,6 @@ dnl ===========================================================================
 
 CHECK_JSON=yes
 HAVE_JSON=no
-AC_SUBST([HAVE_JSON])
 
 AC_ARG_WITH([json],
        [AS_HELP_STRING([--without-json], [build without json-c support])],
@@ -810,6 +809,7 @@ fi
 
 AC_SUBST([JSON_CPPFLAGS])
 AC_SUBST([JSON_LDFLAGS])
+AC_SUBST([HAVE_JSON])
 
 fi dnl }
 
index 87dba66069eca85a27f1d8fc8adc0024f112d783..1f9d0a21788d2d3af49ea9fff84f176984b55f29 100644 (file)
@@ -180,49 +180,59 @@ parse_geojson_polygon(json_object *geojson, int *hasz,  int root_srid)
        POINTARRAY **ppa;
        json_object* rings = NULL;
        int i = 0, j = 0;
-       int ring = 0;
+       int nRings = 0;
 
        rings = findMemberByName( geojson, "coordinates" );
-       if ( ! rings ) {
+       if ( ! rings ) 
+       {
                geojson_lwerror("Unable to find 'coordinates' in GeoJSON string", 4);
-    return NULL;
-  }
+               return NULL;
+       }
+
+       if ( json_type_array != json_object_get_type(rings) )
+       {
+               geojson_lwerror("The 'coordinates' in GeoJSON string are not an array", 4);
+               return NULL;
+       }
+       
+       nRings = json_object_array_length( rings );
+
+       if ( ! nRings )
+       {
+               return (LWGEOM *)lwpoly_construct_empty(root_srid, 0, 0);
+       }
 
        ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
 
-       if( json_type_array == json_object_get_type( rings ) )
+       int nPoints;
+       json_object* points = NULL;
+       ppa[0] = ptarray_construct_empty(1, 0, 1);
+       points = json_object_array_get_idx( rings, 0 );
+       nPoints = json_object_array_length( points );
+
+       for (i=0; i < nPoints; i++ )
+       {
+               json_object* coords = NULL;
+               coords = json_object_array_get_idx( points, i );
+               parse_geojson_coord(coords, hasz, ppa[0]);
+       }
+
+       for(i = 1; i < nRings; ++i)
        {
                int nPoints;
-               json_object* points = NULL;
-               ppa[0] = ptarray_construct_empty(1, 0, 1);
-               ring = json_object_array_length( rings );
-               points = json_object_array_get_idx( rings, 0 );
+               ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa, sizeof(POINTARRAY*) * (i + 1));
+               ppa[i] = ptarray_construct_empty(1, 0, 1);
+               points = json_object_array_get_idx( rings, i );
                nPoints = json_object_array_length( points );
-
-               for (i=0; i < nPoints; i++ )
+               for (j=0; j < nPoints; j++ )
                {
                        json_object* coords = NULL;
-                       coords = json_object_array_get_idx( points, i );
-                       parse_geojson_coord(coords, hasz, ppa[0]);
-               }
-
-               for(i = 1; i < ring; ++i)
-               {
-                       int nPoints;
-                       ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa, sizeof(POINTARRAY*) * (i + 1));
-                       ppa[i] = ptarray_construct_empty(1, 0, 1);
-                       points = json_object_array_get_idx( rings, i );
-                       nPoints = json_object_array_length( points );
-                       for (j=0; j < nPoints; j++ )
-                       {
-                               json_object* coords = NULL;
-                               coords = json_object_array_get_idx( points, j );
-                               parse_geojson_coord(coords, hasz, ppa[i]);
-                       }
+                       coords = json_object_array_get_idx( points, j );
+                       parse_geojson_coord(coords, hasz, ppa[i]);
                }
        }
 
-       geom = (LWGEOM *) lwpoly_construct(root_srid, NULL, ring, ppa);
+       geom = (LWGEOM *) lwpoly_construct(root_srid, NULL, nRings, ppa);
        return geom;
 }
 
index 36135b0d9d82d8090b25207134842e52803060b0..4b3d7672f338ad5a44c6d6914a3afd92739dbd6e 100644 (file)
@@ -16,3 +16,6 @@ SELECT '#2130', ST_NPoints(ST_GeomFromGeoJSON('{"type":"MultiPolygon","coordinat
 
 -- #2216 --
 SELECT '#2216', ST_NPoints(ST_GeomFromGeoJSON('{"type":"MultiPolygon","coordinates":[[[[4,0],[0,-4],[-4,0],[0,4],[4,0]],[[2,0],[0,2],[-2,0],[0,-2],[2,0]]],[[[24,0],[20,-4],[16,0],[20,4],[24,0]],[[22,0],[20,2],[18,0],[20,-2],[22,0]]],[[[44,0],[40,-4],[36,0],[40,4],[44,0]],[[42,0],[40,2],[38,0],[40,-2],[42,0]]]]}'));
+
+-- #2619 --
+SELECT '#2619', ST_AsText(ST_GeomFromGeoJSON('{"type":"Polygon","bbox":[1,5,2,6],"coordinates":[]}'));
\ No newline at end of file
index 701bb5f58b31106915cb0381745e8a2c8c05fffd..30ae16684460ba341705afac41fa8fc8e2245939 100644 (file)
@@ -9,3 +9,4 @@ ERROR:  Unable to find 'coordinates' in GeoJSON string
 ERROR:  unexpected character (at offset 0)
 #2130|8
 #2216|30
+#2619|POLYGON EMPTY