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

Paul Ramsey pramsey at cleverelephant.ca
Wed Jun 15 13:47:11 PDT 2016


Author: pramsey
Date: 2016-06-15 13:47:10 -0700 (Wed, 15 Jun 2016)
New Revision: 14957

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


Modified: trunk/liblwgeom/lwgeom_geos.c
===================================================================
--- trunk/liblwgeom/lwgeom_geos.c	2016-06-15 20:37:32 UTC (rev 14956)
+++ trunk/liblwgeom/lwgeom_geos.c	2016-06-15 20:47:10 UTC (rev 14957)
@@ -332,7 +332,7 @@
 	/*
 	LWGEOM *tmp;
 	*/
-	uint32_t ngeoms, i;
+	uint32_t ngeoms, i, j;
 	int geostype;
 #if LWDEBUG_LEVEL >= 4
 	char *wkt;
@@ -444,18 +444,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: trunk/regress/tickets.sql
===================================================================
--- trunk/regress/tickets.sql	2016-06-15 20:37:32 UTC (rev 14956)
+++ trunk/regress/tickets.sql	2016-06-15 20:47:10 UTC (rev 14957)
@@ -966,5 +966,29 @@
 SELECT '#3470', ST_Polygonize(ARRAY[NULL]::geometry[]) IS NULL;
 SELECT '#3470b', ST_Area(ST_Polygonize(ARRAY[NULL, 'LINESTRING (0 0, 10 0, 10 10)', NULL, 'LINESTRING (0 0, 10 10)', NULL]::geometry[]));
 
+-- #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: trunk/regress/tickets_expected
===================================================================
--- trunk/regress/tickets_expected	2016-06-15 20:37:32 UTC (rev 14956)
+++ trunk/regress/tickets_expected	2016-06-15 20:47:10 UTC (rev 14957)
@@ -294,3 +294,4 @@
 #3437e|5
 #3470|t
 #3470b|50
+#3579|f|t



More information about the postgis-tickets mailing list