]> granicus.if.org Git - postgis/commitdiff
Parse error on incorrectly nested GeoJSON input
authorPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 10 Sep 2018 22:19:00 +0000 (22:19 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 10 Sep 2018 22:19:00 +0000 (22:19 +0000)
Closes #4164

git-svn-id: http://svn.osgeo.org/postgis/trunk@16725 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_in_geojson.c
liblwgeom/lwin_geojson.c

index bb3ce749d16a7a09fc4e713e0a9c8239b64a9ff0..d2daacd5188647c5de7dde801a87efc4297115da 100644 (file)
@@ -151,6 +151,13 @@ static void in_geojson_test_bbox(void)
 
 static void in_geojson_test_geoms(void)
 {
+       
+       /* Incorrect Polygon (#4164) */
+       // do_geojson_test(
+       //     "POLYGON((0 0,0 5,5 5,5 0,0 0))",
+       //      "{\"type\": \"Polygon\", \"coordinates\": [[0,0],[0,5],[5, 5],[5,0],[0,0]]}",
+       //      NULL);
+
        /* Linestring */
        do_geojson_test(
            "LINESTRING(0 1,2 3,4 5)",
index f9b4161abd2b0b50c40c6e267415dc14feb5944a..6f7afcc8d46b6bcbe3b4df3ad1897a8f3bc47f52 100644 (file)
@@ -273,7 +273,17 @@ parse_geojson_polygon(json_object *geojson, int *hasz, int root_srid)
                {
                        json_object* coords = NULL;
                        coords = json_object_array_get_idx( points, j );
-                       parse_geojson_coord(coords, hasz, ppa[i]);
+                       if (LW_FAILURE == parse_geojson_coord(coords, hasz, ppa[i]))
+                       {
+                               int k;
+                               for (k = 0; k <= i; k++)
+                               {
+                                       ptarray_free(ppa[k]);
+                               }
+                               lwfree(ppa);
+                               geojson_lwerror("The 'coordinates' in GeoJSON polygon are not sufficiently nested", 4);
+                               return NULL;                            
+                       }
                }
        }