]> granicus.if.org Git - postgis/commitdiff
Added check of band # passed to ST_DumpAsPolygons. Fixes #1514.
authorBborie Park <bkpark at ucdavis.edu>
Tue, 31 Jan 2012 14:46:42 +0000 (14:46 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Tue, 31 Jan 2012 14:46:42 +0000 (14:46 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8973 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rt_pg.c

index 87606d62c339c9b6eb5c2bfb870357fdbc809caf..a4294e49b9ad78dc739897681d4521ed67d504c1 100644 (file)
@@ -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 */
 
         /**