[postgis-tickets] r16683 - Fix backend crash on ST_OffsetCurve failure

Daniel Baston dbaston at gmail.com
Tue Aug 7 05:57:31 PDT 2018


Author: dbaston
Date: 2018-08-07 17:57:31 -0700 (Tue, 07 Aug 2018)
New Revision: 16683

Modified:
   trunk/NEWS
   trunk/liblwgeom/cunit/cu_geos.c
   trunk/liblwgeom/lwgeom_geos.c
Log:
Fix backend crash on ST_OffsetCurve failure

Closes #4143



Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2018-08-07 10:34:01 UTC (rev 16682)
+++ trunk/NEWS	2018-08-08 00:57:31 UTC (rev 16683)
@@ -10,6 +10,7 @@
     multiple dots (Raúl Marín, Paul Ramsey)
   - #4140, Use user-provided CFLAGS in address standardizer and the
     topology module (Raúl Marín)
+  - #4143, Fix backend crash when ST_OffsetCurve fails (Dan Baston)
 
   See PostGIS 2.5.0 section for full details
 

Modified: trunk/liblwgeom/cunit/cu_geos.c
===================================================================
--- trunk/liblwgeom/cunit/cu_geos.c	2018-08-07 10:34:01 UTC (rev 16682)
+++ trunk/liblwgeom/cunit/cu_geos.c	2018-08-08 00:57:31 UTC (rev 16683)
@@ -110,6 +110,20 @@
 }
 
 static void
+test_geos_offsetcurve_crash(void)
+{
+	// Test for Trac #4143. The specific output or lack of output is not important,
+	// we're just testing that we don't crash.
+	LWGEOM* in = lwgeom_from_wkt("LINESTRING(362194.505 5649993.044,362197.451 5649994.125,362194.624 5650001.876,362189.684 5650000.114,362192.542 5649992.324,362194.505 5649993.044)", LW_PARSER_CHECK_NONE);
+	LWGEOM* out = lwgeom_offsetcurve(in, -0.045, 8, 2, 5.0);
+
+	lwgeom_free(in);
+	if (out) {
+		lwgeom_free(out);
+	}
+}
+
+static void
 test_geos_makevalid(void)
 {
 	uint8_t* wkb;
@@ -165,5 +179,6 @@
 	PG_ADD_TEST(suite, test_geos_subdivide);
 	PG_ADD_TEST(suite, test_geos_linemerge);
 	PG_ADD_TEST(suite, test_geos_offsetcurve);
+	PG_ADD_TEST(suite, test_geos_offsetcurve_crash);
 	PG_ADD_TEST(suite, test_geos_makevalid);
 }

Modified: trunk/liblwgeom/lwgeom_geos.c
===================================================================
--- trunk/liblwgeom/lwgeom_geos.c	2018-08-07 10:34:01 UTC (rev 16682)
+++ trunk/liblwgeom/lwgeom_geos.c	2018-08-08 00:57:31 UTC (rev 16683)
@@ -1363,6 +1363,7 @@
 {
 	int32_t srid = RESULT_SRID(geom);
 	LWGEOM *result = NULL;
+	LWGEOM *noded = NULL;
 	if (srid == SRID_INVALID) return NULL;
 
 	if (lwgeom_dimension(geom) != 1)
@@ -1371,40 +1372,41 @@
 		return NULL;
 	}
 
-	switch (geom->type)
+	while (!result)
 	{
-	case LINETYPE:
-		result = lwline_offsetcurve(lwgeom_as_lwline(geom), size, quadsegs, joinStyle, mitreLimit);
-		break;
-	case COLLECTIONTYPE:
-	case MULTILINETYPE:
-		result = lwcollection_offsetcurve(lwgeom_as_lwcollection(geom), size, quadsegs, joinStyle, mitreLimit);
-		break;
-	default:
-		lwerror("%s: unsupported geometry type: %s", __func__, lwtype_name(geom->type));
-		return NULL;
-	}
+		switch (geom->type)
+		{
+		case LINETYPE:
+			result = lwline_offsetcurve(lwgeom_as_lwline(geom), size, quadsegs, joinStyle, mitreLimit);
+			break;
+		case COLLECTIONTYPE:
+		case MULTILINETYPE:
+			result = lwcollection_offsetcurve(lwgeom_as_lwcollection(geom), size, quadsegs, joinStyle, mitreLimit);
+			break;
+		default:
+			lwerror("%s: unsupported geometry type: %s", __func__, lwtype_name(geom->type));
+			return NULL;
+		}
 
-	if (!result)
-	{
-		/* Node the input geometry and try again */
-		LWGEOM* noded = lwgeom_node(geom);
-		if (!noded)
+		if (result)
+			return result;
+		else if (!noded)
 		{
-			lwerror("%s: cannot node input", __func__);
+			noded = lwgeom_node(geom);
+			if (!noded)
+			{
+				lwfree(noded);
+				lwerror("lwgeom_offsetcurve: cannot node input");
+				return NULL;
+			}
+			geom = noded;
+		}
+		else
+		{
+			lwerror("lwgeom_offsetcurve: noded geometry cannot be offset");
 			return NULL;
 		}
-
-		result = lwgeom_offsetcurve(noded, size, quadsegs, joinStyle, mitreLimit);
-		lwfree(noded);
 	}
-
-	if (!result)
-	{
-		lwerror("%s: noded geometry cannot be offset", __func__);
-		return NULL;
-	}
-
 	return result;
 }
 



More information about the postgis-tickets mailing list