MapServer / MapServer-import

3 stars 2 forks source link

SHAPEPATH is neglected when rendering big raster images #1748

Open tbonfort opened 12 years ago

tbonfort commented 12 years ago

Reporter: malfet@jscc.ru Date: 2006/04/17 - 16:29

If mapserver is running on 32-bit arch and one of the layers are big raster file, that have to be rendered 
by GDAL library, SHAPEPATH is neglected when calling to GDALOpen
Please, look at following code in msDrawRasterLayerLow:

    msBuildPath3(szPath, map->mappath, map->shapepath, filename);
    f = fopen( szPath, "rb");
    if(!f) {
      memset( dd, 0, 8 );
      strcpy( szPath, filename );
    } else {
      fread(dd,8,1,f); /* read some bytes to try and identify the file */
      fclose(f);
    }
    ....
    hDS = GDALOpen(szPath, GA_ReadOnly );
fopen may return NULL, while errno will be equal to EFBIG, but SHAPEPATH will be discarded.
But functionality will again be normal, if one will check this case
    f = fopen( szPath, "rb");
    if(!f) {
      memset( dd, 0, 8 );
#ifndef USE_GDAL
      strcpy( szPath, filename );
#else
       if ( errno != EFBIG)
           strcpy( szPath, filename );
#endif
    } else {
tbonfort commented 12 years ago

Author: fwarmerdam Date: 2006/04/18 - 19:30

Nikita, 

I was aware of this problem, but I wasn't aware I could check for 
the EFBIG error.  I have modified the patch a bit to work on platforms
without EFBIG defined, and to be a bit more explanitory.

    /*
    ** Try to open the file, and read the first 8 bytes as a signature. 
    ** If the open fails for a reason other than "bigness" then we use
    ** the filename unaltered by path logic since it might be something
    ** very virtual.
    */
    f = fopen( szPath, "rb");
    if(!f) {
      memset( dd, 0, 8 );
#ifdef EFBIG
      if( errno != EFBIG )
          strcpy( szPath, filename );
#else
      strcpy( szPath, filename );
#endif
    } else {
      fread(dd,8,1,f); /* read some bytes to try and identify the file */
      fclose(f);
    }

I have only incorporated this patch into 4.9.  It could go into 4.8 branch 
but I'm a bit nervous about it still. 

Please reopen if you feel this should go into 4.8 branch.