[postgis-tickets] [SCM] PostGIS branch master updated. 3.3.0rc2-667-g2c76ff2d0

git at osgeo.org git at osgeo.org
Sun Feb 26 19:36:47 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, master has been updated
       via  2c76ff2d0c9964f4fe26042e3e494eb466286afc (commit)
      from  1d9d3f137aa7afadc38398576b1b93a337e475bb (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 2c76ff2d0c9964f4fe26042e3e494eb466286afc
Author: Regina Obe <lr at pcorp.us>
Date:   Sun Feb 26 22:32:24 2023 -0500

    Reject infinite coordinates in _ST_BestSRID
    
    to prevent crash on ARM (maybe other systems too)
    References #5347 for PostGIS 3.4.0
    
    Also change convert to gserialized logic to use newer syntax

diff --git a/postgis/geography_measurement.c b/postgis/geography_measurement.c
index 3e5818629..1911472c3 100644
--- a/postgis/geography_measurement.c
+++ b/postgis/geography_measurement.c
@@ -804,29 +804,45 @@ Datum geography_bestsrid(PG_FUNCTION_ARGS)
 	int empty2 = LW_FALSE;
 	double xwidth, ywidth;
 	POINT2D center;
-	Datum d1 = PG_GETARG_DATUM(0);
+	LWGEOM *lwgeom;
 
 	/* Get our geometry objects loaded into memory. */
-	g1 = (GSERIALIZED*)PG_DETOAST_DATUM(d1);
+	g1 = PG_GETARG_GSERIALIZED_P(0);
 	/* Synchronize our box types */
 	gbox1.flags = gserialized_get_lwflags(g1);
 	/* Calculate if the geometry is empty. */
 	empty1 = gserialized_is_empty(g1);
+
+	/* Convert g1 to LWGEOM type */
+	lwgeom = lwgeom_from_gserialized(g1);
+
 	/* Calculate a geocentric bounds for the objects */
 	if ( ! empty1 && gserialized_get_gbox_p(g1, &gbox1) == LW_FAILURE )
 		elog(ERROR, "Error in geography_bestsrid calling gserialized_get_gbox_p(g1, &gbox1)");
 
 	POSTGIS_DEBUGF(4, "calculated gbox = %s", gbox_to_string(&gbox1));
 
+	if ( !lwgeom_isfinite(lwgeom) ) {
+		elog(ERROR, "Error in geography_bestsrid calling with infinite coordinate geographies");
+	}
+	lwgeom_free(lwgeom);
+
 	/* If we have a unique second argument, fill in all the necessary variables. */
 	if (PG_NARGS() > 1)
 	{
-		Datum d2 = PG_GETARG_DATUM(1);
-		g2 = (GSERIALIZED*)PG_DETOAST_DATUM(d2);
+		g2 = PG_GETARG_GSERIALIZED_P(1);
 		gbox2.flags = gserialized_get_lwflags(g2);
 		empty2 = gserialized_is_empty(g2);
 		if ( ! empty2 && gserialized_get_gbox_p(g2, &gbox2) == LW_FAILURE )
 			elog(ERROR, "Error in geography_bestsrid calling gserialized_get_gbox_p(g2, &gbox2)");
+
+		/* Convert g2 to LWGEOM type */
+		lwgeom = lwgeom_from_gserialized(g2);
+
+		if ( !lwgeom_isfinite(lwgeom) ) {
+			elog(ERROR, "Error in geography_bestsrid calling with second arg infinite coordinate geographies");
+		}
+		lwgeom_free(lwgeom);
 	}
 	/*
 	** If no unique second argument, copying the box for the first
diff --git a/regress/core/bestsrid.sql b/regress/core/bestsrid.sql
index 832122c84..2437a4d02 100644
--- a/regress/core/bestsrid.sql
+++ b/regress/core/bestsrid.sql
@@ -23,3 +23,9 @@ select 180, -60, _ST_BestSRID(ST_Point(180, -60));
 -- World mercator
 select 'world', _ST_BestSRID(ST_Point(-160, -40), ST_Point(160, 40));
 
+-- infinite coords
+SELECT _ST_BestSRID(ST_Point('-infinity', 'infinity'));
+
+SELECT '#5347', ST_Intersection('0102000020E610000005000000000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F'::geography,
+                       '0101000020E6100000000000000000F07F000000000000F07F'::geography);
+
diff --git a/regress/core/bestsrid_expected b/regress/core/bestsrid_expected
index f939e24af..3947d96ec 100644
--- a/regress/core/bestsrid_expected
+++ b/regress/core/bestsrid_expected
@@ -125,3 +125,8 @@
 -180|-60|999160
 180|-60|999160
 world|999000
+NOTICE:  Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY
+ERROR:  Error in geography_bestsrid calling with infinite coordinate geographies
+NOTICE:  Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY at character 33
+NOTICE:  Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY at character 257
+ERROR:  Error in geography_bestsrid calling with infinite coordinate geographies

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

Summary of changes:
 postgis/geography_measurement.c | 24 ++++++++++++++++++++----
 regress/core/bestsrid.sql       |  6 ++++++
 regress/core/bestsrid_expected  |  5 +++++
 3 files changed, 31 insertions(+), 4 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list