From f32b7827e9a0ed666494851b4695cd7aa7310f4c Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Mon, 23 Mar 2015 16:23:20 +0000 Subject: [PATCH] Fix ST_DumpValues() crasher when cleaning. Ticket #3086 git-svn-id: http://svn.osgeo.org/postgis/trunk@13390 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 3 ++- raster/rt_pg/rtpg_pixel.c | 20 ++++++++++++-------- raster/test/regress/rt_dumpvalues.sql | 14 +++++++++++++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 07d961b4a..72891b034 100644 --- 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 * diff --git a/raster/rt_pg/rtpg_pixel.c b/raster/rt_pg/rtpg_pixel.c index ba0967c29..364e1fd1d 100644 --- a/raster/rt_pg/rtpg_pixel.c +++ b/raster/rt_pg/rtpg_pixel.c @@ -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); diff --git a/raster/test/regress/rt_dumpvalues.sql b/raster/test/regress/rt_dumpvalues.sql index b5f7ee439..73a130de7 100644 --- a/raster/test/regress/rt_dumpvalues.sql +++ b/raster/test/regress/rt_dumpvalues.sql @@ -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; -- 2.40.0