[postgis-tickets] r14669 - #3461 ST_GeomFromKML crashes Postgres when there are innerBoundaryIs and no outerBoundaryIs

Paul Ramsey pramsey at cleverelephant.ca
Tue Feb 23 08:57:57 PST 2016


Author: pramsey
Date: 2016-02-23 08:57:57 -0800 (Tue, 23 Feb 2016)
New Revision: 14669

Modified:
   trunk/postgis/lwgeom_in_kml.c
Log:
#3461 ST_GeomFromKML crashes Postgres when there are innerBoundaryIs and no outerBoundaryIs


Modified: trunk/postgis/lwgeom_in_kml.c
===================================================================
--- trunk/postgis/lwgeom_in_kml.c	2016-02-23 16:57:25 UTC (rev 14668)
+++ trunk/postgis/lwgeom_in_kml.c	2016-02-23 16:57:57 UTC (rev 14669)
@@ -401,6 +401,7 @@
 	int ring;
 	xmlNodePtr xa, xb;
 	POINTARRAY **ppa = NULL;
+	int outer_rings = 0;
 
 	for (xa = xnode->children ; xa != NULL ; xa = xa->next)
 	{
@@ -431,9 +432,13 @@
 				ptarray_append_point(ppa[0], &pt, LW_TRUE);
 				lwpgnotice("forced closure on an un-closed KML polygon");
 			}
+			outer_rings++;
 		}
 	}
-
+	
+	if (outer_rings != 1)
+		lwpgerror("invalid KML representation");
+		 
 	for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
 	{
 
@@ -449,8 +454,7 @@
 			if (!is_kml_namespace(xb, false)) continue;
 			if (strcmp((char *) xb->name, "LinearRing")) continue;
 
-			ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
-			                               sizeof(POINTARRAY*) * (ring + 1));
+			ppa = (POINTARRAY**) lwrealloc(ppa, sizeof(POINTARRAY*) * (ring + 1));
 			ppa[ring] = parse_kml_coordinates(xb->children, hasz);
 
 			if (ppa[ring]->npoints < 4)



More information about the postgis-tickets mailing list