[postgis-tickets] [SCM] PostGIS branch stable-3.0 updated. 3.0.8-10-g0abc351f3

git at osgeo.org git at osgeo.org
Sun Mar 12 23:48:30 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.0 has been updated
       via  0abc351f3e4ca9ea8af38502dd9d33589737ec9a (commit)
      from  7596f7e6a6708c00784fbcca151b121bf4515d82 (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 0abc351f3e4ca9ea8af38502dd9d33589737ec9a
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)
    Closes #5347 for PostGIS 3.0.9
    
    Also change convert to gserialized logic to use newer syntax

diff --git a/NEWS b/NEWS
index a0e67e4f2..18cb8650a 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.0.8
 2022/11/11
diff --git a/postgis/geography_measurement.c b/postgis/geography_measurement.c
index 95c9019d2..1c2e93d45 100644
--- a/postgis/geography_measurement.c
+++ b/postgis/geography_measurement.c
@@ -821,29 +821,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