[postgis-tickets] r16504 - 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 01:53:19 PDT 2018


Author: robe
Date: 2018-03-28 01:53:19 -0700 (Wed, 28 Mar 2018)
New Revision: 16504

Modified:
   branches/2.4/NEWS
   branches/2.4/doc/reference_raster.xml
   branches/2.4/raster/rt_pg/rtpg_mapalgebra.c
   branches/2.4/raster/test/regress/tickets.sql
   branches/2.4/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).
References #3055 for PostGIS 2.4.4, 
also minor doc fix references #2925 for PostGIS 2.4.4

Modified: branches/2.4/NEWS
===================================================================
--- branches/2.4/NEWS	2018-03-28 08:37:30 UTC (rev 16503)
+++ branches/2.4/NEWS	2018-03-28 08:53:19 UTC (rev 16504)
@@ -1,7 +1,9 @@
 PostGIS 2.4.4dev
-2018/MM/DD
+2018/04/DD
 
  * Bug fixes *
+  - #3055, [raster] ST_Clip() on a raster without band crashes the server
+          (Regina Obe)
   - #3942, geojson: Do not include private header for json-c >= 0.13
            (Björn Esser)
   - #3952, ST_Transform fails in parallel mode (Paul Ramsey)

Modified: branches/2.4/doc/reference_raster.xml
===================================================================
--- branches/2.4/doc/reference_raster.xml	2018-03-28 08:37:30 UTC (rev 16503)
+++ branches/2.4/doc/reference_raster.xml	2018-03-28 08:53:19 UTC (rev 16504)
@@ -1817,7 +1817,7 @@
 						  </informalfigure></para>
                 <programlisting>
 -- this will output a black circle taking up 150 x 150 pixels --
-SELECT ST_AsPNG(ST_AsRaster(ST_Buffer(ST_Point(1,5),10),150, 150, '2BUI'));</programlisting>
+SELECT ST_AsPNG(ST_AsRaster(ST_Buffer(ST_Point(1,5),10),150, 150));</programlisting>
 
  <para><informalfigure>
 							<mediaobject>

Modified: branches/2.4/raster/rt_pg/rtpg_mapalgebra.c
===================================================================
--- branches/2.4/raster/rt_pg/rtpg_mapalgebra.c	2018-03-28 08:37:30 UTC (rev 16503)
+++ branches/2.4/raster/rt_pg/rtpg_mapalgebra.c	2018-03-28 08:53:19 UTC (rev 16504)
@@ -3022,8 +3022,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.4/raster/test/regress/tickets.sql
===================================================================
--- branches/2.4/raster/test/regress/tickets.sql	2018-03-28 08:37:30 UTC (rev 16503)
+++ branches/2.4/raster/test/regress/tickets.sql	2018-03-28 08:53:19 UTC (rev 16504)
@@ -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.4/raster/test/regress/tickets_expected
===================================================================
--- branches/2.4/raster/test/regress/tickets_expected	2018-03-28 08:37:30 UTC (rev 16503)
+++ branches/2.4/raster/test/regress/tickets_expected	2018-03-28 08:53:19 UTC (rev 16504)
@@ -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