[SCM] PostGIS branch stable-3.4 updated. 3.4.6-21-g631c35f7c

git at osgeo.org git at osgeo.org
Tue Jun 23 16:10:19 PDT 2026


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.4 has been updated
       via  631c35f7cd08585be7383383d2de00b0c1f4d1e7 (commit)
       via  3bcc9f453d36161bf31547eefd2bef8602c8a28c (commit)
      from  80c17c66b8b47bf5d090ed7e9571d91508e24cba (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 631c35f7cd08585be7383383d2de00b0c1f4d1e7
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Tue Jun 23 16:09:55 2026 -0700

    New for avoid Inf loop in Geohash calculation

diff --git a/NEWS b/NEWS
index a736cdc7b..b2371141b 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ PostGIS 3.4.7
   - #5357, ST_LineFromEncodedPolyline dropping close points (Paul Ramsey)
   - OSSFuzz 525554772, avoid signed integer overflow (Even Rouault)
   - OSSFuzz 525548201, avoid overly nested inputs (Darafei Praliaskouski)
+ - Avoid Inf loop in Geohash calculation (Paul Ramsey)
 
 
 PostGIS 3.4.6

commit 3bcc9f453d36161bf31547eefd2bef8602c8a28c
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Tue Jun 23 23:01:11 2026 +0000

    Avoid Inf loop in Geohash calculation

diff --git a/liblwgeom/cunit/cu_algorithm.c b/liblwgeom/cunit/cu_algorithm.c
index 97cf1d8d0..375aa364f 100644
--- a/liblwgeom/cunit/cu_algorithm.c
+++ b/liblwgeom/cunit/cu_algorithm.c
@@ -3,7 +3,7 @@
  * PostGIS - Spatial Types for PostgreSQL
  * http://postgis.net
  * Copyright 2008 Paul Ramsey
- * Copyright 2018 Darafei Praliaskouski, me at komzpa.net
+ * Copyright 2018, 2026 Darafei Praliaskouski <me at komzpa.net>
  *
  * This is free software; you can redistribute and/or modify it under
  * the terms of the GNU General Public Licence. See the COPYING file.
@@ -952,6 +952,15 @@ static void test_geohash_precision(void)
 	//printf("precision %d\n",precision);
 	CU_ASSERT_EQUAL(precision, 7);
 
+	/* Tiny bbox near south pole: lon-halving loop hits IEEE 754 convergence
+	** before straddling the midpoint — old code hung here. */
+	bbox.xmin = -72.70493954792298;
+	bbox.xmax = -72.70493954792298;
+	bbox.ymin = -89.90561212126683;
+	bbox.ymax = -89.90561212126681;
+	precision = lwgeom_geohash_precision(bbox, &bounds);
+	CU_ASSERT(precision >= 0 && precision <= 20);
+
 }
 
 static void test_geohash_point(void)
@@ -981,7 +990,6 @@ static void test_geohash(void)
 	LWLINE *lwline = NULL;
 	LWMLINE *lwmline = NULL;
 	lwvarlena_t *geohash = NULL;
-
 	lwpoint = (LWPOINT*)lwgeom_from_wkt("POINT(23.0 25.2)", LW_PARSER_CHECK_NONE);
 	geohash = lwgeom_geohash((LWGEOM*)lwpoint,0);
 	//printf("\ngeohash %s\n",geohash);
diff --git a/liblwgeom/lwalgorithm.c b/liblwgeom/lwalgorithm.c
index 1697320c1..61c145380 100644
--- a/liblwgeom/lwalgorithm.c
+++ b/liblwgeom/lwalgorithm.c
@@ -540,6 +540,8 @@ int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2)
 
 static char *base32 = "0123456789bcdefghjkmnpqrstuvwxyz";
 
+#define GEOHASH_MAX_DOUBLE_PRECISION_CHARS 20
+
 /*
 ** Calculate the geohash, iterating downwards and gaining precision.
 ** From geohash-native.c, (c) 2008 David Troy <dave at roundhousetech.com>
@@ -732,7 +734,7 @@ int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds)
 	{
 		/* It's a point. Doubles have 51 bits of precision.
 		** 2 * 51 / 5 == 20 */
-		return 20;
+		return GEOHASH_MAX_DOUBLE_PRECISION_CHARS;
 	}
 
 	lonmin = -180.0;
@@ -744,6 +746,11 @@ int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds)
 	** bounds of our rectangle. */
 	while ( 1 )
 	{
+		double old_lonmin = lonmin;
+		double old_lonmax = lonmax;
+		double old_latmin = latmin;
+		double old_latmax = latmax;
+
 		lonwidth = lonmax - lonmin;
 		latwidth = latmax - latmin;
 		latmaxadjust = lonmaxadjust = latminadjust = lonminadjust = 0.0;
@@ -760,6 +767,9 @@ int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds)
 		{
 			lonmin += lonminadjust;
 			lonmax += lonmaxadjust;
+			/* Stop before counting bits that no longer move the double bounds. */
+			if (lonmin == old_lonmin && lonmax == old_lonmax)
+				break;
 			/* Each adjustment cycle corresponds to 2 bits of storage in the
 			** geohash.	*/
 			precision++;
@@ -782,6 +792,9 @@ int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds)
 		{
 			latmin += latminadjust;
 			latmax += latmaxadjust;
+			/* Stop before counting bits that no longer move the double bounds. */
+			if (latmin == old_latmin && latmax == old_latmax)
+				break;
 			/* Each adjustment cycle corresponds to 2 bits of storage in the
 			** geohash.	*/
 			precision++;
@@ -800,7 +813,8 @@ int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds)
 
 	/* Each geohash character (base32) can contain 5 bits of information.
 	** We are returning the precision in characters, so here we divide. */
-	return precision / 5;
+	precision /= 5;
+	return precision > GEOHASH_MAX_DOUBLE_PRECISION_CHARS ? GEOHASH_MAX_DOUBLE_PRECISION_CHARS : precision;
 }
 
 

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

Summary of changes:
 NEWS                           |  1 +
 liblwgeom/cunit/cu_algorithm.c | 12 ++++++++++--
 liblwgeom/lwalgorithm.c        | 18 ++++++++++++++++--
 3 files changed, 27 insertions(+), 4 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list