From 1f9ae3ee6dbf794bdc3f41330fec8c4dc323e7e7 Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Tue, 31 Jan 2012 14:46:42 +0000 Subject: [PATCH] Added check of band # passed to ST_DumpAsPolygons. Fixes #1514. git-svn-id: http://svn.osgeo.org/postgis/trunk@8973 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_pg/rt_pg.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index 87606d62c..a4294e49b 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -819,6 +819,8 @@ Datum RASTER_dumpAsWKTPolygons(PG_FUNCTION_ARGS) /* stuff done only on the first call of the function */ if (SRF_IS_FIRSTCALL()) { + int numbands; + POSTGIS_RT_DEBUG(2, "RASTER_dumpAsWKTPolygons first call"); /* create a function context for cross-call persistence */ @@ -847,6 +849,14 @@ Datum RASTER_dumpAsWKTPolygons(PG_FUNCTION_ARGS) POSTGIS_RT_DEBUGF(3, "band %d", nband); + numbands = rt_raster_get_num_bands(raster); + if (nband < 1 || nband > numbands) { + elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL"); + rt_raster_destroy(raster); + MemoryContextSwitchTo(oldcontext); + SRF_RETURN_DONE(funcctx); + } + /* Polygonize raster */ /** -- 2.50.1