[postgis-tickets] r14959 - #3579, crash in LWGEOM2GEOS

Paul Ramsey pramsey at cleverelephant.ca
Wed Jun 15 14:17:15 PDT 2016


Author: pramsey
Date: 2016-06-15 14:17:14 -0700 (Wed, 15 Jun 2016)
New Revision: 14959

Modified:
   branches/2.0/NEWS
   branches/2.0/liblwgeom/lwgeom_geos.c
   branches/2.0/regress/tickets.sql
   branches/2.0/regress/tickets_expected
Log:
#3579, crash in LWGEOM2GEOS


Modified: branches/2.0/NEWS
===================================================================
--- branches/2.0/NEWS	2016-06-15 21:12:04 UTC (rev 14958)
+++ branches/2.0/NEWS	2016-06-15 21:17:14 UTC (rev 14959)
@@ -22,6 +22,7 @@
   - #3461, ST_GeomFromKML crashes Postgres when there are 
            innerBoundaryIs and no outerBoundaryIs
   - #3565, ST_SetPoint can crash backend
+  - #3579, Crash in LWGEOM2GEOS
 
 
 PostGIS 2.0.7

Modified: branches/2.0/liblwgeom/lwgeom_geos.c
===================================================================
--- branches/2.0/liblwgeom/lwgeom_geos.c	2016-06-15 21:12:04 UTC (rev 14958)
+++ branches/2.0/liblwgeom/lwgeom_geos.c	2016-06-15 21:17:14 UTC (rev 14959)
@@ -246,7 +246,7 @@
 	/*
 	LWGEOM *tmp;
 	*/
-	uint32_t ngeoms, i;
+	uint32_t ngeoms, i, j;
 	int geostype;
 #if LWDEBUG_LEVEL >= 4
 	char *wkt;
@@ -377,18 +377,23 @@
 		if ( ngeoms > 0 )
 			geoms = malloc(sizeof(GEOSGeom)*ngeoms);
 
-		for (i=0; i<ngeoms; ++i)
+		for (i=0, j=0; i<ngeoms; i++)
 		{
-			GEOSGeometry* g = LWGEOM2GEOS(lwc->geoms[i]);
+			GEOSGeometry* g;
+
+			if( lwgeom_is_empty(lwc->geoms[i]) )
+				continue;
+
+			g = LWGEOM2GEOS(lwc->geoms[i]);
 			if ( ! g )
 			{
 				while (i) GEOSGeom_destroy(geoms[--i]);
 				free(geoms);
 				return NULL;
 			}
-			geoms[i] = g;
+			geoms[j++] = g;
 		}
-		g = GEOSGeom_createCollection(geostype, geoms, ngeoms);
+		g = GEOSGeom_createCollection(geostype, geoms, j);
 		if ( geoms ) free(geoms);
 		if ( ! g ) return NULL;
 		break;

Modified: branches/2.0/regress/tickets.sql
===================================================================
--- branches/2.0/regress/tickets.sql	2016-06-15 21:12:04 UTC (rev 14958)
+++ branches/2.0/regress/tickets.sql	2016-06-15 21:17:14 UTC (rev 14959)
@@ -777,5 +777,29 @@
 -- #3565
 SELECT '#3565',ST_SetPoint(st_geomfromtext('LINESTRING EMPTY'), 0, ST_MakePoint(1,1));
 
+-- #3579
+with
+        params as (
+        select
+            11 :: float as sidewalk_offset,
+            1 :: float  as epsilon
+    ),
+        road as (
+-- L-shaped road, 10 m
+        select 'SRID=3857;LINESTRING(10 0, 0 0, 0 10)' :: geometry as geom
+    ),
+        sidewalks as (
+        select ST_Collect(
+                   ST_OffsetCurve(geom, sidewalk_offset),
+                   ST_OffsetCurve(geom, -sidewalk_offset)
+               ) geom
+        from road, params
+    )
+select
+    '#3579', ST_Intersects(road.geom, sidewalks.geom),
+-- should be false
+    ST_Intersects(ST_Buffer(road.geom, sidewalk_offset + epsilon), sidewalks.geom) -- should be true
+from road, sidewalks, params;
+
 -- Clean up
 DELETE FROM spatial_ref_sys;

Modified: branches/2.0/regress/tickets_expected
===================================================================
--- branches/2.0/regress/tickets_expected	2016-06-15 21:12:04 UTC (rev 14958)
+++ branches/2.0/regress/tickets_expected	2016-06-15 21:17:14 UTC (rev 14959)
@@ -245,3 +245,4 @@
 #2168|5340.76237395|5340.76237395|0
 #2870|Point[G]
 ERROR:  Cannot set point values on EMPTY geometry, use ST_AddPoint to add points
+#3579|f|t



More information about the postgis-tickets mailing list