[postgis-tickets] [SCM] PostGIS branch stable-3.1 updated. 3.1.8-10-g18e7a7c65

git at osgeo.org git at osgeo.org
Sun Mar 12 23:46:44 PDT 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.1 has been updated
       via  18e7a7c656ec723886fba82e3c6c852a8dd8e9a9 (commit)
      from  f6530540615d210b74bc34abef0185530f56270f (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 18e7a7c656ec723886fba82e3c6c852a8dd8e9a9
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.1.9
    
    Also change convert to gserialized logic to use newer syntax

diff --git a/NEWS b/NEWS
index 8e890a436..0810fb8c0 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ xxxx/xx/xx
           (Regina Obe, Paul Ramsey)
   - #5344, Include topology id sequence state in dumps (Sandro Santilli)
   - #5288, ST_LineCrossingDirection multi-cross error (Paul Ramsey)
+  - #5347, _ST_BestSRID crashes on ARM with infinite geometries (Regina Obe)
 
 
 PostGIS 3.1.8
diff --git a/postgis/geography_measurement.c b/postgis/geography_measurement.c
index bea5d9ec9..b5afdaefe 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:
 NEWS                            |  1 +
 postgis/geography_measurement.c | 24 ++++++++++++++++++++----
 regress/core/bestsrid.sql       |  6 ++++++
 regress/core/bestsrid_expected  |  5 +++++
 4 files changed, 32 insertions(+), 4 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list