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

Paul Ramsey pramsey at cleverelephant.ca
Wed Jun 15 13:37:33 PDT 2016


Author: pramsey
Date: 2016-06-15 13:37:32 -0700 (Wed, 15 Jun 2016)
New Revision: 14956

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


Modified: branches/2.2/NEWS
===================================================================
--- branches/2.2/NEWS	2016-06-15 16:47:22 UTC (rev 14955)
+++ branches/2.2/NEWS	2016-06-15 20:37:32 UTC (rev 14956)
@@ -10,6 +10,7 @@
   - #3571, Install desktop file and application icons 
            for shp2pgsql-gui (Sebastiaan Couwenberg)
   - #3573, Operator <<->> incorrectly calculates m distance
+  - #3579, Crash in LWGEOM2GEOS
 
 
 PostGIS 2.2.2

Modified: branches/2.2/liblwgeom/lwgeom_geos.c
===================================================================
--- branches/2.2/liblwgeom/lwgeom_geos.c	2016-06-15 16:47:22 UTC (rev 14955)
+++ branches/2.2/liblwgeom/lwgeom_geos.c	2016-06-15 20:37:32 UTC (rev 14956)
@@ -327,7 +327,7 @@
 	/*
 	LWGEOM *tmp;
 	*/
-	uint32_t ngeoms, i;
+	uint32_t ngeoms, i, j;
 	int geostype;
 #if LWDEBUG_LEVEL >= 4
 	char *wkt;
@@ -456,18 +456,24 @@
 		if ( ngeoms > 0 )
 			geoms = malloc(sizeof(GEOSGeom)*ngeoms);
 
+		j = 0;
 		for (i=0; i<ngeoms; ++i)
 		{
-			GEOSGeometry* g = LWGEOM2GEOS(lwc->geoms[i], 0);
+			GEOSGeometry* g;
+			
+			if( lwgeom_is_empty(lwc->geoms[i]) )
+				continue;
+			
+			g = LWGEOM2GEOS(lwc->geoms[i], 0);
 			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.2/regress/tickets.sql
===================================================================
--- branches/2.2/regress/tickets.sql	2016-06-15 16:47:22 UTC (rev 14955)
+++ branches/2.2/regress/tickets.sql	2016-06-15 20:37:32 UTC (rev 14956)
@@ -950,5 +950,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.2/regress/tickets_expected
===================================================================
--- branches/2.2/regress/tickets_expected	2016-06-15 16:47:22 UTC (rev 14955)
+++ branches/2.2/regress/tickets_expected	2016-06-15 20:37:32 UTC (rev 14956)
@@ -292,3 +292,4 @@
 #3470|t
 #3470b|50
 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