[gdal-dev] WMS MINRESOLUTION can lead to overflow of raster dimensions
Timothy Astle
timothy.astle at caris.com
Mon Nov 23 13:01:31 PST 2015
I'm trying to open a WMS dataset using the minimally documented
MINRESOLUTION option. (http://www.gdal.org/frmt_wms.html)
When providing a way-too-fine resolution, I manage to create a raster
that exceeds GDALs 32-bit integer based dimensions. Below shows what
I'm seeing. You can see that one of the dimensions has overflowed.
gdal_translate.exe -of PNG
"http://nowcoast.noaa.gov:80/wms/com.esri.wms.Esrimap/obs?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=RAS_RIDGE_NEXRAD&SRS=EPSG:4326&BBOX=-180,-90,180,90&transparent=true&MINRESOLUTION=8.98315e-008"
my.png
ERROR 1: Invalid dataset dimensions : -2147483648 x 2003751468
GDALOpen failed - 1
Invalid dataset dimensions : -2147483648 x 2003751468
I'm wondering if it'd make sense to handle the kind of input that would
cause this problem to surface. Looking at the calculations made in the
wmsdriver, when a MINRESOLUTION is provided the following code is where
the issue happens:
if (osMinResolution.size() != 0)
{
double dfMinResolution = CPLAtofM(osMinResolution);
while (nOverviewCount > 20)
{
nOverviewCount --;
dfMinResolution *= 2;
}
nXSize = (int) ((dfMaxX - dfMinX) / dfMinResolution + 0.5);
nYSize = (int) ((dfMaxY - dfMinY) / dfMinResolution + 0.5);
}
Would it make sense to do something as follows? (Note: I haven't tried
this yet, I'm just soliciting early feedback so please bare with me )
if (osMinResolution.size() != 0)
{
double dfMinResolution = CPLAtofM(osMinResolution);
while (nOverviewCount > 20)
{
nOverviewCount --;
dfMinResolution *= 2;
}
// *** Changes here ***
// Determine a suitable resolution that doesn't overflow max int.
double dXSize = ((dfMaxX - dfMinX) / dfMinResolution + 0.5);
double dYSize = ((dfMaxY - dfMinY) / dfMinResolution + 0.5);
while (dXSize > INT_MAX || dYSize > INT_MAX)
{
nOverviewCount --;
dfMinResolution *= 2;
dXSize = ((dfMaxX - dfMinX) / dfMinResolution + 0.5);
dYSize = ((dfMaxY - dfMinY) / dfMinResolution + 0.5);
}
nXSize = (int) dXSize;
nYSize = (int) dYSize;
}
Any thoughts?
Tim Astle
More information about the gdal-dev
mailing list