Changeset 12316

Show
Ignore:
Timestamp:
10/04/07 10:02:38 (1 year ago)
Author:
warmerdam
Message:

restrict data request when reading tile/strips (#1179)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/frmts/gtiff/geotiff.cpp

    r12294 r12316  
    399399         
    400400/* -------------------------------------------------------------------- */ 
     401/*      The bottom most partial tiles and strips are sometimes only     */ 
     402/*      partially encoded.  This code reduces the requested data so     */ 
     403/*      an error won't be reported in this case. (#1179)                */ 
     404/* -------------------------------------------------------------------- */ 
     405    int nBlockReqSize = nBlockBufSize; 
     406 
     407    if( (nBlockYOff+1) * nBlockYSize > nRasterYSize ) 
     408    { 
     409        nBlockReqSize = (nBlockBufSize / nBlockYSize)  
     410            * (nBlockYSize - (((nBlockYOff+1) * nBlockYSize) % nRasterYSize)); 
     411    } 
     412 
     413/* -------------------------------------------------------------------- */ 
    401414/*      Handle the case of a strip or tile that doesn't exist yet.      */ 
    402415/*      Just set to zeros and return.                                   */ 
     
    416429        || poGDS->nPlanarConfig == PLANARCONFIG_SEPARATE ) 
    417430    { 
     431        if( nBlockReqSize < nBlockBufSize ) 
     432            memset( pImage, 0, nBlockBufSize ); 
     433 
    418434        if( TIFFIsTiled( poGDS->hTIFF ) ) 
    419435        { 
    420436            if( TIFFReadEncodedTile( poGDS->hTIFF, nBlockId, pImage, 
    421                                      nBlockBufSize ) == -1 ) 
     437                                     nBlockReqSize ) == -1 ) 
    422438            { 
    423439                memset( pImage, 0, nBlockBufSize ); 
     
    431447        { 
    432448            if( TIFFReadEncodedStrip( poGDS->hTIFF, nBlockId, pImage, 
    433                                       nBlockBufSize ) == -1 ) 
     449                                      nBlockReqSize ) == -1 ) 
    434450            { 
    435451                memset( pImage, 0, nBlockBufSize ); 
     
    12591275 
    12601276{ 
    1261     return poColorTable; 
     1277    return poColorTable; 
    12621278} 
    12631279 
     
    18321848     
    18331849/* -------------------------------------------------------------------- */ 
     1850/*      The bottom most partial tiles and strips are sometimes only     */ 
     1851/*      partially encoded.  This code reduces the requested data so     */ 
     1852/*      an error won't be reported in this case. (#1179)                */ 
     1853/* -------------------------------------------------------------------- */ 
     1854    int nBlockReqSize = nBlockBufSize; 
     1855    int nBlockYOff = nBlockId % nBlocksPerBand; 
     1856 
     1857    if( (int)((nBlockYOff+1) * nBlockYSize) > nRasterYSize ) 
     1858    { 
     1859        nBlockReqSize = (nBlockBufSize / nBlockYSize)  
     1860            * (nBlockYSize - (((nBlockYOff+1) * nBlockYSize) % nRasterYSize)); 
     1861        memset( pabyBlockBuf, 0, nBlockBufSize ); 
     1862    } 
     1863 
     1864/* -------------------------------------------------------------------- */ 
    18341865/*      If we don't have this block already loaded, and we know it      */ 
    18351866/*      doesn't yet exist on disk, just zero the memory buffer and      */ 
     
    18491880    { 
    18501881        if( TIFFReadEncodedTile(hTIFF, nBlockId, pabyBlockBuf, 
    1851                                 nBlockBufSize) == -1 ) 
     1882                                nBlockReqSize) == -1 ) 
    18521883        { 
    18531884            /* Once TIFFError() is properly hooked, this can go away */ 
     
    18631894    { 
    18641895        if( TIFFReadEncodedStrip(hTIFF, nBlockId, pabyBlockBuf, 
    1865                                  nBlockBufSize) == -1 ) 
     1896                                 nBlockReqSize) == -1 ) 
    18661897        { 
    18671898            /* Once TIFFError() is properly hooked, this can go away */