[postgis-tickets] [SCM] PostGIS branch stable-3.3 updated. 3.3.2-24-gbf77e55a2

git at osgeo.org git at osgeo.org
Thu Feb 16 12:16:55 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.3 has been updated
       via  bf77e55a2f125b967a691e8408daf5e96ad3e4cd (commit)
       via  a46840c41d6f5e6671da4654db2cd4a033e7e0fe (commit)
      from  6ae0b4e89b05ae76beaacb0d07408b1e4028d1f5 (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 bf77e55a2f125b967a691e8408daf5e96ad3e4cd
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, to avoid crash/hang.
    for PostGIS 3.3.3
    Closes #5320

diff --git a/NEWS b/NEWS
index 4f4059a94..c658a011e 100644
--- a/NEWS
+++ b/NEWS
@@ -15,7 +15,8 @@ YYYY/MM/DD
   - #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 crashes on infinite coordinates (Regina Obe)
+  - #5315, #5318, #5319, #5320 crashes on infinite coordinates
+          (Regina Obe, Paul Ramsey)
 
 
 PostGIS 3.3.2
diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in
index 7ffffa8a7..46f3619c4 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 c7a1d1cd5..c4e2e33ac 100644
--- a/liblwgeom/lwgeom.c
+++ b/liblwgeom/lwgeom.c
@@ -2679,3 +2679,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_geos.c b/postgis/lwgeom_geos.c
index f8b3dcd7c..7ff9ff68b 100644
--- a/postgis/lwgeom_geos.c
+++ b/postgis/lwgeom_geos.c
@@ -874,23 +874,32 @@ Datum ST_SimplifyPolygonHull(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");
 
@@ -901,9 +910,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)
@@ -912,7 +921,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);
 }
 
diff --git a/regress/core/tickets.sql b/regress/core/tickets.sql
index d4cd9da20..9e0266426 100644
--- a/regress/core/tickets.sql
+++ b/regress/core/tickets.sql
@@ -1480,3 +1480,5 @@ 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 55e387201..23d969b7e 100644
--- a/regress/core/tickets_expected
+++ b/regress/core/tickets_expected
@@ -464,3 +464,4 @@ ERROR:  Line has no points
 #5139|100000
 #5139|1000000
 ERROR:  Geometry contains invalid coordinates
+ERROR:  Geometry contains invalid coordinates

commit a46840c41d6f5e6671da4654db2cd4a033e7e0fe
Author: Regina Obe <lr at pcorp.us>
Date:   Thu Feb 16 02:41:52 2023 -0500

    Prevent crash on infinite coordinates
    for PostGIS 3.3.3
    References #5319 ST_SetPoint
    References #5315 ST_Buffer
    References #5318 ST_MaximumnInscribedCircle

diff --git a/NEWS b/NEWS
index 597f2013f..4f4059a94 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,7 @@ YYYY/MM/DD
   - #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 crashes on infinite coordinates (Regina Obe)
 
 
 PostGIS 3.3.2
diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c
index 1bf6f0bc4..72e61bf77 100644
--- a/postgis/lwgeom_functions_basic.c
+++ b/postgis/lwgeom_functions_basic.c
@@ -2444,6 +2444,7 @@ 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");
@@ -2455,6 +2456,12 @@ Datum LWGEOM_setpoint_linestring(PG_FUNCTION_ARGS)
 		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 e481008d3..f8b3dcd7c 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();
@@ -959,6 +966,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 590d64c13..d4cd9da20 100644
--- a/regress/core/tickets.sql
+++ b/regress/core/tickets.sql
@@ -1478,3 +1478,5 @@ 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);
diff --git a/regress/core/tickets_expected b/regress/core/tickets_expected
index 35d4241c0..55e387201 100644
--- a/regress/core/tickets_expected
+++ b/regress/core/tickets_expected
@@ -463,3 +463,4 @@ ERROR:  LWGEOM_addpoint: Invalid offset
 ERROR:  Line has no points
 #5139|100000
 #5139|1000000
+ERROR:  Geometry contains invalid coordinates

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

Summary of changes:
 NEWS                             |  2 ++
 liblwgeom/liblwgeom.h.in         |  6 ++++++
 liblwgeom/lwgeom.c               | 26 +++++++++++++++++++++++++
 postgis/lwgeom_functions_basic.c |  7 +++++++
 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, 88 insertions(+), 9 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list