From: Bborie Park Date: Thu, 31 May 2012 05:46:10 +0000 (+0000) Subject: Explicit error message when dimensions requested exceeds the maximum X-Git-Tag: 2.1.0beta2~954 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=923d8f893193d31b8d9e6ec59f1c6905622f5a94;p=postgis Explicit error message when dimensions requested exceeds the maximum permitted of a raster. git-svn-id: http://svn.osgeo.org/postgis/trunk@9838 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index f6570d3e1..d08c0a230 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -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); diff --git a/raster/rt_core/rt_api.h b/raster/rt_core/rt_api.h index 9fcba016a..70edabc97 100644 --- a/raster/rt_core/rt_api.h +++ b/raster/rt_core/rt_api.h @@ -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