[postgis-tickets] [SCM] PostGIS branch stable-3.2 updated. 3.2.4-7-g0239850ba

git at osgeo.org git at osgeo.org
Thu Feb 16 13:07:06 PST 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, stable-3.2 has been updated
       via  0239850ba81e57240b70b0433d755d6b9091db0e (commit)
      from  15eaa9e0799eeed941e9ca8e19545cb4bce1e4e4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0239850ba81e57240b70b0433d755d6b9091db0e
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Fri Feb 10 12:56:15 2023 -0800

    Prefilter to check for non-finite coordinates before feeding
    ST_SimplifyPreserveTopology, ST_Buffer, ST_SetPoint,
    ST_MinimumInscribedCircle
    to avoid crash/hang.
    References #5320
    References #5315
    References #5318
    References #5319
    for PostGIS 3.2.5

diff --git a/NEWS b/NEWS
index 2e5c5337c..e2b6348c9 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ Proj 6.1+, and PostgreSQL 14+.
   - #5313, Fix memory access issue in ST_InterpolateRaster (Paul Ramsey)
   - #5338, Dump/Restore of raster table fails on
            enforce_coverage_tile_rast constraint (Regina Obe)
+  - #5315, #5318, #5319, #5320 crashes on infinite coordinates
+          (Regina Obe, Paul Ramsey)
 
 PostGIS 3.2.4
 2022/11/12
diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in
index c48d58751..bc74527bf 100644
--- a/liblwgeom/liblwgeom.h.in
+++ b/liblwgeom/liblwgeom.h.in
@@ -912,6 +912,12 @@ extern const GBOX *lwgeom_get_bbox(const LWGEOM *lwgeom);
 */
 extern int lwgeom_is_collection(const LWGEOM *lwgeom);
 
+/**
+* Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
+*/
+extern int lwgeom_isfinite(const LWGEOM *lwgeom);
+
+
 /******************************************************************/
 /* Functions that work on type numbers */
 
diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c
index 12e64327d..4d0f96ef8 100644
--- a/liblwgeom/lwgeom.c
+++ b/liblwgeom/lwgeom.c
@@ -2662,3 +2662,29 @@ lwgeom_boundary(LWGEOM *lwgeom)
 		return NULL;
 	}
 }
+
+int
+lwgeom_isfinite(const LWGEOM *lwgeom)
+{
+	LWPOINTITERATOR* it = lwpointiterator_create(lwgeom);
+	int hasz = lwgeom_has_z(lwgeom);
+	int hasm = lwgeom_has_m(lwgeom);
+
+	while (lwpointiterator_has_next(it))
+	{
+		POINT4D p;
+		lwpointiterator_next(it, &p);
+		int finite = isfinite(p.x) &&
+			isfinite(p.y) &&
+			(hasz ? isfinite(p.z) : 1) &&
+			(hasm ? isfinite(p.m) : 1);
+
+		if (!finite)
+		{
+			lwpointiterator_destroy(it);
+			return LW_FALSE;
+		}
+	}
+	lwpointiterator_destroy(it);
+	return LW_TRUE;
+}
diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c
index c9e7bdcc9..72e61bf77 100644
--- a/postgis/lwgeom_functions_basic.c
+++ b/postgis/lwgeom_functions_basic.c
@@ -2444,15 +2444,24 @@ Datum LWGEOM_setpoint_linestring(PG_FUNCTION_ARGS)
 
 	lwg = lwgeom_from_gserialized(pglwg1);
 	line = lwgeom_as_lwline(lwg);
+
 	if (!line)
 	{
 		elog(ERROR, "First argument must be a LINESTRING");
 		PG_RETURN_NULL();
 	}
+
 	if ( line->points->npoints < 1 ) 	{
 		elog(ERROR, "Line has no points");
 		PG_RETURN_NULL();
 	}
+
+	if (!lwgeom_isfinite(lwg))
+	{
+		elog(ERROR, "Geometry contains invalid coordinate");
+		PG_RETURN_NULL();
+	}
+
 	if (which < 0)
 	{
 		/* Use backward indexing for negative values */
diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c
index 99b9f47c9..203fbb70b 100644
--- a/postgis/lwgeom_geos.c
+++ b/postgis/lwgeom_geos.c
@@ -387,6 +387,13 @@ Datum ST_MaximumInscribedCircle(PG_FUNCTION_ARGS)
 		double width, height, size, tolerance;
 		GBOX gbox;
 		int gtype;
+		LWGEOM *lwg;
+		lwg = lwgeom_from_gserialized(geom);
+		if (!lwgeom_isfinite(lwg))
+		{
+			lwpgerror("Geometry contains invalid coordinates");
+			PG_RETURN_NULL();
+		}
 
 		if (!gserialized_get_gbox_p(geom, &gbox))
 			PG_RETURN_NULL();
@@ -892,23 +899,32 @@ Datum convexhull(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(topologypreservesimplify);
 Datum topologypreservesimplify(PG_FUNCTION_ARGS)
 {
-	GSERIALIZED	*geom1;
+	GSERIALIZED	*gs1;
+	LWGEOM *lwg1;
 	double	tolerance;
 	GEOSGeometry *g1, *g3;
 	GSERIALIZED *result;
 	uint32_t type;
 
-	geom1 = PG_GETARG_GSERIALIZED_P(0);
+	gs1 = PG_GETARG_GSERIALIZED_P(0);
 	tolerance = PG_GETARG_FLOAT8(1);
+	lwg1 = lwgeom_from_gserialized(gs1);
 
 	/* Empty.Simplify() == Empty */
-	type = gserialized_get_type(geom1);
-	if ( gserialized_is_empty(geom1) || type == TINTYPE || type == TRIANGLETYPE )
-		PG_RETURN_POINTER(geom1);
+	type = lwgeom_get_type(lwg1);
+	if (lwgeom_is_empty(lwg1) || type == TINTYPE || type == TRIANGLETYPE)
+		PG_RETURN_POINTER(gs1);
+
+	if (!lwgeom_isfinite(lwg1))
+	{
+		lwpgerror("Geometry contains invalid coordinates");
+		PG_RETURN_NULL();
+	}
 
 	initGEOS(lwpgnotice, lwgeom_geos_error);
 
-	g1 = POSTGIS2GEOS(geom1);
+	g1 = LWGEOM2GEOS(lwg1, LW_TRUE);
+	lwgeom_free(lwg1);
 	if (!g1)
 		HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
 
@@ -919,9 +935,9 @@ Datum topologypreservesimplify(PG_FUNCTION_ARGS)
 
 	POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
 
-	GEOSSetSRID(g3, gserialized_get_srid(geom1));
+	GEOSSetSRID(g3, gserialized_get_srid(gs1));
 
-	result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
+	result = GEOS2POSTGIS(g3, gserialized_has_z(gs1));
 	GEOSGeom_destroy(g3);
 
 	if (!result)
@@ -930,7 +946,7 @@ Datum topologypreservesimplify(PG_FUNCTION_ARGS)
 		PG_RETURN_NULL(); /* never get here */
 	}
 
-	PG_FREE_IF_COPY(geom1, 0);
+	PG_FREE_IF_COPY(gs1, 0);
 	PG_RETURN_POINTER(result);
 }
 
@@ -984,6 +1000,14 @@ Datum buffer(PG_FUNCTION_ARGS)
 		PG_RETURN_POINTER(geometry_serialize(lwg));
 	}
 
+	lwg = lwgeom_from_gserialized(geom1);
+
+	if (!lwgeom_isfinite(lwg))
+	{
+		lwpgerror("Geometry contains invalid coordinates");
+		PG_RETURN_NULL();
+	}
+
 	initGEOS(lwpgnotice, lwgeom_geos_error);
 
 	g1 = POSTGIS2GEOS(geom1);
diff --git a/regress/core/geos39.sql b/regress/core/geos39.sql
index 8885fdd85..4a444a418 100644
--- a/regress/core/geos39.sql
+++ b/regress/core/geos39.sql
@@ -42,3 +42,6 @@ SELECT 'mic-cte' AS name, ST_AsText(st_snaptogrid((ST_MaximumInscribedCircle(ply
 SELECT 'rp-1', ST_AsText(ST_ReducePrecision('POINT(1.412 19.323)', 0.1));
 SELECT 'rp-2', ST_AsText(ST_ReducePrecision('POINT(1.412 19.323)', 1.0));
 SELECT 'rp-3', ST_AsText(ST_ReducePrecision('POINT(1.412 19.323)', 10));
+
+-- ST_MaximumInscribedCircle infinite check https://trac.osgeo.org/postgis/ticket/5318
+SELECT '#5318', ST_MaximumInscribedCircle('0106000020E61000000100000001030000000100000005000000000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F'::geometry) As result;
diff --git a/regress/core/geos39_expected b/regress/core/geos39_expected
index 06ebbd417..ec9be2b85 100644
--- a/regress/core/geos39_expected
+++ b/regress/core/geos39_expected
@@ -8,3 +8,4 @@ mic-cte|POINT(49.512 49.512)
 rp-1|POINT(1.4 19.3)
 rp-2|POINT(1 19)
 rp-3|POINT(0 20)
+ERROR:  Geometry contains invalid coordinates
diff --git a/regress/core/setpoint.sql b/regress/core/setpoint.sql
index 51519ac54..553e50309 100644
--- a/regress/core/setpoint.sql
+++ b/regress/core/setpoint.sql
@@ -26,3 +26,6 @@ SELECT ST_asewkt(ST_SetPoint('LINESTRING(0 0 0 0, 1 1 1 1, 2 2 2 2, 4 4 4 4)', 2
 SELECT ST_asewkt(ST_SetPoint('LINESTRING(0 0 0 0, 1 1 1 1, 2 2 2 2, 4 4 4 4)', 1, 'POINTM(90 91 92)'));
 SELECT ST_asewkt(ST_SetPoint('LINESTRING(0 0 0 0, 1 1 1 1, 2 2 2 2, 4 4 4 4)', 0, 'POINT(90 91 92 93)'));
 
+-- https://trac.osgeo.org/postgis/ticket/5319
+SELECT '#5319', ST_SetPoint('0102000020E610000005000000000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F'::geometry, 1,ST_GeomFromText('POINT(0 0)',4326)  )  As result;
+
diff --git a/regress/core/setpoint_expected b/regress/core/setpoint_expected
index 210195c40..cbc622b07 100644
--- a/regress/core/setpoint_expected
+++ b/regress/core/setpoint_expected
@@ -11,3 +11,4 @@ LINESTRING(0 0 0 0,1 1 1 1,2 2 2 2,90 91 0 0)
 LINESTRING(0 0 0 0,1 1 1 1,90 91 92 0,4 4 4 4)
 LINESTRING(0 0 0 0,90 91 0 92,2 2 2 2,4 4 4 4)
 LINESTRING(90 91 92 93,1 1 1 1,2 2 2 2,4 4 4 4)
+ERROR:  Geometry contains invalid coordinate
diff --git a/regress/core/tickets.sql b/regress/core/tickets.sql
index 6517ad827..1c1133a08 100644
--- a/regress/core/tickets.sql
+++ b/regress/core/tickets.sql
@@ -1461,3 +1461,7 @@ reset max_parallel_workers_per_gather;
 reset force_parallel_mode;
 
 SET client_min_messages TO NOTICE;
+-- https://trac.osgeo.org/postgis/ticket/5315
+SELECT '#5315', ST_Buffer('0106000020E86400000100000001030000000100000005000000000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F'::geometry, 1);
+
+SELECT '#5320', ST_SimplifyPreserveTopology('0106000020E86400000100000001030000000100000005000000000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F'::geometry, 1);
diff --git a/regress/core/tickets_expected b/regress/core/tickets_expected
index cd0a08c05..3c26ffc4e 100644
--- a/regress/core/tickets_expected
+++ b/regress/core/tickets_expected
@@ -463,3 +463,5 @@ ERROR:  LWGEOM_addpoint: Invalid offset
 ERROR:  Line has no points
 #5139|100000
 #5139|1000000
+ERROR:  Geometry contains invalid coordinates
+ERROR:  Geometry contains invalid coordinates

-----------------------------------------------------------------------

Summary of changes:
 NEWS                             |  2 ++
 liblwgeom/liblwgeom.h.in         |  6 ++++++
 liblwgeom/lwgeom.c               | 26 +++++++++++++++++++++++++
 postgis/lwgeom_functions_basic.c |  9 +++++++++
 postgis/lwgeom_geos.c            | 42 +++++++++++++++++++++++++++++++---------
 regress/core/geos39.sql          |  3 +++
 regress/core/geos39_expected     |  1 +
 regress/core/setpoint.sql        |  3 +++
 regress/core/setpoint_expected   |  1 +
 regress/core/tickets.sql         |  4 ++++
 regress/core/tickets_expected    |  2 ++
 11 files changed, 90 insertions(+), 9 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list