]> granicus.if.org Git - postgis/commitdiff
Fix ST_DumpValues() crasher when cleaning. Ticket #3086
authorBborie Park <bkpark at ucdavis.edu>
Mon, 23 Mar 2015 16:23:20 +0000 (16:23 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Mon, 23 Mar 2015 16:23:20 +0000 (16:23 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13390 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
raster/rt_pg/rtpg_pixel.c
raster/test/regress/rt_dumpvalues.sql

diff --git a/NEWS b/NEWS
index 07d961b4afbef5f38d3799086308fa822ce42cda..72891b034eaabec9ff9cbac38ba86b685eea59dd 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -91,7 +91,8 @@ PostGIS 2.2.0
            max extent constraint
   - #3020, ST_AddBand out-db bug where height using width value
   - #3061, Allow duplicate points in JSON, GML, GML ST_GeomFrom* functions
-
+  - #3086, ST_DumpValues() crashes backend on cleanup with invalid
+           band indexes
 
  * Code refactoring *
 
index ba0967c29c9de2e569f9e99e06e3a0c24f3cb3a8..364e1fd1d55c04ddb6a060d964760761696a8cef 100644 (file)
@@ -174,20 +174,23 @@ static rtpg_dumpvalues_arg rtpg_dumpvalues_arg_init() {
 static void rtpg_dumpvalues_arg_destroy(rtpg_dumpvalues_arg arg) {
        int i = 0;
 
-       if (arg->numbands) {
+       if (arg->numbands > 0) {
                if (arg->nbands != NULL)
                        pfree(arg->nbands);
 
-               for (i = 0; i < arg->numbands; i++) {
-                       if (arg->values[i] != NULL)
-                               pfree(arg->values[i]);
+               if (arg->values != NULL) {
+                       for (i = 0; i < arg->numbands; i++) {
 
-                       if (arg->nodata[i] != NULL)
-                               pfree(arg->nodata[i]);
-               }
+                               if (arg->values[i] != NULL)
+                                       pfree(arg->values[i]);
+
+                               if (arg->nodata[i] != NULL)
+                                       pfree(arg->nodata[i]);
+                       }
 
-               if (arg->values != NULL)
                        pfree(arg->values);
+               }
+
                if (arg->nodata != NULL)
                        pfree(arg->nodata);
        }
@@ -363,6 +366,7 @@ Datum RASTER_dumpValues(PG_FUNCTION_ARGS)
                        }
 
                }
+               /* no bands specified, return all bands */
                else {
                        arg1->numbands = numbands;
                        arg1->nbands = palloc(sizeof(int) * arg1->numbands);
index b5f7ee4390767c74058f9b927cdf5b98a64107da..73a130de7159d807c0cb1a2f3a9dbcf675210cc2 100644 (file)
@@ -98,4 +98,16 @@ ORDER BY rid;
 
 DROP TABLE IF EXISTS raster_dumpvalues;
 
-SELECT (ST_DumpValues(ST_AddBand(ST_MakeEmptyRaster(0, 0, 0, 0, 1), ARRAY[ROW(NULL, '8BUI', 255, 0),ROW(NULL, '16BUI', 1, 2)]::addbandarg[]))).*
+SELECT (ST_DumpValues(ST_AddBand(ST_MakeEmptyRaster(0, 0, 0, 0, 1), ARRAY[ROW(NULL, '8BUI', 255, 0),ROW(NULL, '16BUI', 1, 2)]::addbandarg[]))).*;
+
+
+-- #3086
+DROP TABLE IF EXISTS raster_tile;
+CREATE TABLE raster_tile AS
+    WITH foo AS (
+        SELECT ST_AddBand(ST_AddBand(ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 1, 0), 2, '8BUI', 10, 0) AS rast UNION ALL
+        SELECT ST_AddBand(ST_AddBand(ST_MakeEmptyRaster(3, 3, 3, 0, 1, -1, 0, 0, 0), 1, '8BUI', 2, 0), 2, '8BUI', 20, 0) AS rast 
+    )
+    SELECT ST_Union(rast) AS rast FROM foo;
+WITH foo AS (SELECT ST_Tile(rast, 3, 3, TRUE) AS rast FROM raster_tile) SELECT (ST_DumpValues(rast, array[1,2,3])).* FROM foo;
+DROP TABLE IF EXISTS raster_tile;