[postgis-tickets] r16506 - Fix crasher in raster when fed an empty raster (note was tempted to change the def of empty raster to include raster with no bands but not sure where else that is used, so just revised the clip check to not try to clip if no bands).

Regina Obe lr at pcorp.us
Wed Mar 28 02:07:16 PDT 2018


Author: robe
Date: 2018-03-28 02:07:16 -0700 (Wed, 28 Mar 2018)
New Revision: 16506

Modified:
   branches/2.2/NEWS
   branches/2.2/raster/rt_pg/rtpg_mapalgebra.c
   branches/2.2/raster/test/regress/tickets.sql
   branches/2.2/raster/test/regress/tickets_expected
Log:
Fix crasher in raster when fed an empty raster (note was tempted to change the def of empty raster to include raster with no bands but not sure where else that is used, so just revised the clip check to not try to clip if no bands).
Closes #3055 for PostGIS 2.2.7
reorder NEWS tickets numerically

Modified: branches/2.2/NEWS
===================================================================
--- branches/2.2/NEWS	2018-03-28 09:02:04 UTC (rev 16505)
+++ branches/2.2/NEWS	2018-03-28 09:07:16 UTC (rev 16506)
@@ -2,11 +2,13 @@
 2018/xx/xx
 
  * Bug Fixes *
+  - #3055, [raster] ST_Clip() on a raster without band crashes the server
+          (Regina Obe)
   - #3965, ST_ClusterKMeans used to lose some clusters on initialization
            (Darafei Praliaskouski)
   - #3978, Fix KNN when upgrading from 2.1 or older (Sandro Santilli)
+  - #4017, lwgeom lexer memory corruption (Peter E)
   - #4055, ST_ClusterIntersecting dropping SRID (Daniel Baston)
-  - #4017, lwgeom lexer memory corruption (Peter E)
 
 
 PostGIS 2.2.6

Modified: branches/2.2/raster/rt_pg/rtpg_mapalgebra.c
===================================================================
--- branches/2.2/raster/rt_pg/rtpg_mapalgebra.c	2018-03-28 09:02:04 UTC (rev 16505)
+++ branches/2.2/raster/rt_pg/rtpg_mapalgebra.c	2018-03-28 09:07:16 UTC (rev 16506)
@@ -3025,8 +3025,8 @@
 	}
 
 	/* raster is empty, return empty raster */
-	if (rt_raster_is_empty(arg->raster)) {
-		elog(NOTICE, "Input raster is empty. Returning empty raster");
+	if (rt_raster_is_empty(arg->raster) || rt_raster_get_num_bands(arg->raster) == 0) {
+		elog(NOTICE, "Input raster is empty or has no bands. Returning empty raster");
 
 		rtpg_clip_arg_destroy(arg);
 		PG_FREE_IF_COPY(pgraster, 0);

Modified: branches/2.2/raster/test/regress/tickets.sql
===================================================================
--- branches/2.2/raster/test/regress/tickets.sql	2018-03-28 09:02:04 UTC (rev 16505)
+++ branches/2.2/raster/test/regress/tickets.sql	2018-03-28 09:07:16 UTC (rev 16506)
@@ -112,3 +112,8 @@
 DROP TABLE IF EXISTS test_raster_scale_small;
 
 SET client_min_messages TO DEFAULT;
+
+/******************************************************************************
+ #3055 ST_Clip() on a raster without band crashes the server
+******************************************************************************/
+SELECT ST_SummaryStats(ST_Clip(ST_MakeEmptyRaster(42, 42, 0, 0, 1.0, 1.0, 0, 0, 4269), ST_MakeEnvelope(0, 0, 20, 20, 4269)));

Modified: branches/2.2/raster/test/regress/tickets_expected
===================================================================
--- branches/2.2/raster/test/regress/tickets_expected	2018-03-28 09:02:04 UTC (rev 16505)
+++ branches/2.2/raster/test/regress/tickets_expected	2018-03-28 09:07:16 UTC (rev 16506)
@@ -12,3 +12,5 @@
 t
 test_raster_scale_small|rast||1
 ERROR:  new row for relation "test_raster_scale_small" violates check constraint "enforce_scaley_rast"
+NOTICE:  Input raster is empty or has no bands. Returning empty raster
+NOTICE:  Invalid band index (must use 1-based). Returning NULL



More information about the postgis-tickets mailing list