[postgis-tickets] r16550 - ST_ClusterKMeans crash on NULL and EMPTY

Darafei komzpa at gmail.com
Sat Apr 21 06:20:22 PDT 2018


Author: komzpa
Date: 2018-04-21 06:20:22 -0700 (Sat, 21 Apr 2018)
New Revision: 16550

Modified:
   branches/2.4/NEWS
   branches/2.4/liblwgeom/lwkmeans.c
   branches/2.4/regress/lwgeom_regress.sql
   branches/2.4/regress/lwgeom_regress_expected
Log:
ST_ClusterKMeans crash on NULL and EMPTY

Closes #4071



Modified: branches/2.4/NEWS
===================================================================
--- branches/2.4/NEWS	2018-04-21 13:17:14 UTC (rev 16549)
+++ branches/2.4/NEWS	2018-04-21 13:20:22 UTC (rev 16550)
@@ -1,3 +1,11 @@
+PostGIS 2.4.5
+2018/xx/xx
+
+  * Bug Fixes and Enchantments
+
+  - #4071, ST_ClusterKMeans crash on NULL/EMPTY fixed (Darafei Praliaskouski)
+
+
 PostGIS 2.4.4
 2018/04/08
 

Modified: branches/2.4/liblwgeom/lwkmeans.c
===================================================================
--- branches/2.4/liblwgeom/lwkmeans.c	2018-04-21 13:17:14 UTC (rev 16549)
+++ branches/2.4/liblwgeom/lwkmeans.c	2018-04-21 13:20:22 UTC (rev 16550)
@@ -200,7 +200,16 @@
 		{
 			if (seen[j] == closest)
 			{
-				closest = (closest + 1) % config.num_objs;
+				int k, t;
+				for (k = 1; k < config.num_objs; k++)
+				{
+					t = (closest + k) % config.num_objs;
+					if (config.objs[t])
+					{
+						closest = t;
+						break;
+					}
+				}
 				j = 0;
 			}
 			else

Modified: branches/2.4/regress/lwgeom_regress.sql
===================================================================
--- branches/2.4/regress/lwgeom_regress.sql	2018-04-21 13:17:14 UTC (rev 16549)
+++ branches/2.4/regress/lwgeom_regress.sql	2018-04-21 13:20:22 UTC (rev 16550)
@@ -135,3 +135,11 @@
 SELECT 'BoundingDiagonal6', ST_AsEwkt(ST_BoundingDiagonal(
     'SRID=3857;POLYGON M EMPTY'::geometry
 ));
+
+-- check that null and empty is handled in the clustering
+select '#4071', count(distinct a), count(distinct b), count(distinct c)  from
+(select
+	ST_ClusterKMeans(geom, 1) over () a,
+	ST_ClusterKMeans(geom, 2) over () b,
+	ST_ClusterKMeans(geom, 3) over () c
+from (values (null::geometry), ('POINT(1 1)'), ('POINT EMPTY'), ('POINT(0 0)'), ('POINT(4 4)')) as g (geom)) z;

Modified: branches/2.4/regress/lwgeom_regress_expected
===================================================================
--- branches/2.4/regress/lwgeom_regress_expected	2018-04-21 13:17:14 UTC (rev 16549)
+++ branches/2.4/regress/lwgeom_regress_expected	2018-04-21 13:20:22 UTC (rev 16550)
@@ -21,3 +21,4 @@
 BoundingDiagonal4|SRID=3857;LINESTRING(-1 -2 -8 2,1 2 3 9)
 BoundingDiagonal5|SRID=3857;LINESTRINGM(4 4 0,5 4 1)
 BoundingDiagonal6|SRID=3857;LINESTRINGM EMPTY
+#4071|2|3|4



More information about the postgis-tickets mailing list