[SCM] PostGIS branch master updated. 3.6.0rc2-661-g7f9442711
git at osgeo.org
git at osgeo.org
Tue Jun 23 16:02:12 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, master has been updated
via 7f94427119f424f36bf7a0b0d40dcdc32e2b6fdf (commit)
from e8ca3455460303c9a758862f0437d514f19fda34 (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 7f94427119f424f36bf7a0b0d40dcdc32e2b6fdf
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 9d1519f65..ec5b7de38 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.
@@ -998,6 +998,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)
@@ -1027,7 +1036,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 75d8b3549..2f3f1e98a 100644
--- a/liblwgeom/lwalgorithm.c
+++ b/liblwgeom/lwalgorithm.c
@@ -548,6 +548,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>
@@ -740,7 +742,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;
@@ -752,6 +754,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;
@@ -768,6 +775,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++;
@@ -790,6 +800,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++;
@@ -808,7 +821,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:
liblwgeom/cunit/cu_algorithm.c | 12 ++++++++++--
liblwgeom/lwalgorithm.c | 18 ++++++++++++++++--
2 files changed, 26 insertions(+), 4 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list