]> granicus.if.org Git - postgis/commitdiff
Explicit error message when dimensions requested exceeds the maximum
authorBborie Park <bkpark at ucdavis.edu>
Thu, 31 May 2012 05:46:10 +0000 (05:46 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Thu, 31 May 2012 05:46:10 +0000 (05:46 +0000)
permitted of a raster.

git-svn-id: http://svn.osgeo.org/postgis/trunk@9838 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_core/rt_api.h

index f6570d3e14e93afaddd40b0b2aa6ec95ab2b0894..d08c0a23081af0f77e1e509e513f7413b693e14e 100644 (file)
@@ -1179,9 +1179,7 @@ rt_band_new_inline(
                return NULL;
        }
 
-       RASTER_DEBUGF(3, "Created rt_band @ %p with pixtype %s",
-               band, rt_pixtype_name(pixtype)
-       );
+       RASTER_DEBUGF(3, "Created rt_band @ %p with pixtype %s", band, rt_pixtype_name(pixtype));
 
        band->pixtype = pixtype;
        band->offline = 0;
@@ -1194,6 +1192,8 @@ rt_band_new_inline(
        band->isnodata = FALSE;
        band->raster = NULL;
 
+       RASTER_DEBUGF(3, "Created rt_band with dimensions %d x %d", band->width, band->height);
+
        /* properly set nodataval as it may need to be constrained to the data type */
        if (hasnodata && rt_band_set_nodata(band, nodataval) < 0) {
                rterror("rt_band_new_inline: Unable to set NODATA value");
@@ -1843,7 +1843,7 @@ rt_band_set_pixel_line(
                x < 0 || x >= band->width ||
                y < 0 || y >= band->height
        ) {
-               rterror("rt_band_set_pixel_line: Coordinates out of range");
+               rterror("rt_band_set_pixel_line: Coordinates out of range (%d, %d) vs (%d, %d)", x, y, band->width, band->height);
                return 0;
        }
 
@@ -4751,36 +4751,37 @@ rt_band_reclass(rt_band srcband, rt_pixtype pixtype,
 /*- rt_raster --------------------------------------------------------*/
 
 rt_raster
-rt_raster_new(uint16_t width, uint16_t height) {
-    rt_raster ret = NULL;
+rt_raster_new(uint32_t width, uint32_t height) {
+       rt_raster ret = NULL;
 
+       ret = (rt_raster) rtalloc(sizeof (struct rt_raster_t));
+       if (!ret) {
+               rterror("rt_raster_new: Out of virtual memory creating an rt_raster");
+               return NULL;
+       }
 
+       RASTER_DEBUGF(3, "Created rt_raster @ %p", ret);
 
-    ret = (rt_raster) rtalloc(sizeof (struct rt_raster_t));
-    if (!ret) {
-        rterror("rt_raster_new: Out of virtual memory creating an rt_raster");
-        return 0;
-    }
-
-    RASTER_DEBUGF(3, "Created rt_raster @ %p", ret);
-
-    assert(NULL != ret);
-
-    ret->width = width;
+       assert(NULL != ret);
 
-    ret->height = height;
-    ret->scaleX = 1;
-    ret->scaleY = 1;
-    ret->ipX = 0.0;
-    ret->ipY = 0.0;
-    ret->skewX = 0.0;
-    ret->skewY = 0.0;
-    ret->srid = SRID_UNKNOWN;
+       if (width > 65535 || height > 65535) {
+               rterror("rt_raster_new: Dimensions requested exceed the maximum (65535 x 65535) permitted for a raster");
+               return NULL;
+       }
 
-    ret->numBands = 0;
-    ret->bands = 0;
+       ret->width = width;
+       ret->height = height;
+       ret->scaleX = 1;
+       ret->scaleY = 1;
+       ret->ipX = 0.0;
+       ret->ipY = 0.0;
+       ret->skewX = 0.0;
+       ret->skewY = 0.0;
+       ret->srid = SRID_UNKNOWN;
 
-    return ret;
+       ret->numBands = 0;
+       ret->bands = 0; 
+       return ret;
 }
 
 void
@@ -8485,6 +8486,7 @@ rt_raster_from_gdal_dataset(GDALDatasetH ds) {
                rterror("rt_raster_from_gdal_dataset: Out of memory allocating new raster");
                return NULL;
        }
+       RASTER_DEBUGF(3, "Created raster dimensions (width x height): %d x %d", rast->width, rast->height);
 
        /* get raster attributes */
        cplerr = GDALGetGeoTransform(ds, gt);
@@ -8566,6 +8568,7 @@ rt_raster_from_gdal_dataset(GDALDatasetH ds) {
                        return NULL;
                }
                band = rt_raster_get_band(rast, idx);
+               RASTER_DEBUGF(3, "Created band of dimension (width x height): %d x %d", band->width, band->height);
 
                /* this makes use of GDAL's "natural" blocks */
                GDALGetBlockSize(gdband, &nXBlockSize, &nYBlockSize);
index 9fcba016a0e8222baa7d851ce4f2f3d1fad5e449..70edabc97b121d9b241eb7ba3c3761c6a31e3056 100644 (file)
@@ -765,7 +765,7 @@ rt_band rt_band_reclass(rt_band srcband, rt_pixtype pixtype,
  *
  * @return an rt_raster or 0 if out of memory
  */
-rt_raster rt_raster_new(uint16_t width, uint16_t height);
+rt_raster rt_raster_new(uint32_t width, uint32_t height);
 
 /**
  * Construct an rt_raster from a binary WKB representation