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
_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to