Changeset 11168

Show
Ignore:
Timestamp:
04/02/07 13:09:19 (1 year ago)
Author:
dmorissette
Message:

Backport for for MITAB bug 1657 - problem writing collections (GDAL #1541)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.4/gdal/ogr/ogrsf_frmts/mitab/mitab_feature.cpp

    r11101 r11168  
    3434 * Added missing NULL pointer checks in SetPenFromStyleString(), 
    3535 * SetBrushFromStyleString() and SetSymbolFromStyleString() (bug 1670) 
     36 * 
     37 * Revision 1.68  2007/02/22 18:35:53  dmorissette 
     38 * Fixed problem writing collections where MITAB was sometimes trying to 
     39 * read past EOF in write mode (bug 1657). 
    3640 * 
    3741 * Revision 1.66  2006/10/17 14:34:31  dmorissette 
     
    67536757 
    67546758        // And finally move the pointer back to the end of this component 
    6755         if (poCoordBlock->GotoByteInFile(nEndOfObjectPtr, TRUE) != 0) 
     6759        if (poCoordBlock->GotoByteInFile(nEndOfObjectPtr, TRUE, TRUE) != 0) 
    67566760        { 
    67576761            delete poRegionHdr; 
     
    68376841 
    68386842        // And finally move the pointer back to the end of this component 
    6839         if (poCoordBlock->GotoByteInFile(nEndOfObjectPtr, TRUE) != 0) 
     6843        if (poCoordBlock->GotoByteInFile(nEndOfObjectPtr, TRUE, TRUE) != 0) 
    68406844        { 
    68416845            delete poPlineHdr; 
     
    69206924 
    69216925        // And finally move the pointer back to the end of this component 
    6922         if (poCoordBlock->GotoByteInFile(nEndOfObjectPtr, TRUE) != 0) 
     6926        if (poCoordBlock->GotoByteInFile(nEndOfObjectPtr, TRUE, TRUE) != 0) 
    69236927        { 
    69246928            delete poMpointHdr; 
  • branches/1.4/gdal/ogr/ogrsf_frmts/mitab/mitab_priv.h

    r8593 r11168  
    3131 * 
    3232 * $Log: mitab_priv.h,v $ 
     33 * Revision 1.44  2007/02/22 18:35:53  dmorissette 
     34 * Fixed problem writing collections where MITAB was sometimes trying to 
     35 * read past EOF in write mode (bug 1657). 
     36 * 
    3337 * Revision 1.40  2005/10/06 19:15:31  dmorissette 
    3438 * Collections: added support for reading/writing pen/brush/symbol ids and 
     
    758762    int         GotoByteRel(int nOffset); 
    759763    int         GotoByteInBlock(int nOffset); 
    760     int         GotoByteInFile(int nOffset, GBool bForceReadFromFile=FALSE); 
     764    int         GotoByteInFile(int nOffset,  
     765                               GBool bForceReadFromFile = FALSE, 
     766                               GBool bOffsetIsEndOfData = FALSE); 
    761767    void        SetFirstBlockPtr(int nOffset); 
    762768 
  • branches/1.4/gdal/ogr/ogrsf_frmts/mitab/mitab_rawbinblock.cpp

    r8593 r11168  
    3232 * 
    3333 * $Log: mitab_rawbinblock.cpp,v $ 
     34 * Revision 1.10  2007/02/22 18:35:53  dmorissette 
     35 * Fixed problem writing collections where MITAB was sometimes trying to 
     36 * read past EOF in write mode (bug 1657). 
     37 * 
    3438 * Revision 1.8  2005/10/06 19:15:31  dmorissette 
    3539 * Collections: added support for reading/writing pen/brush/symbol ids and 
     
    434438 * or other cases that need to do random access in the file in write mode.) 
    435439 * 
     440 * bOffsetIsEndOfData is set to TRUE to indicate that the nOffset 
     441 * to which we are attempting to go is the end of the used data in this 
     442 * block (we are positioninig ourselves to append data), so if the nOffset  
     443 * corresponds to the beginning of a 512 bytes block then we should really  
     444 * be positioning ourselves at the end of the block that ends at this  
     445 * address instead of at the beginning of the blocks that starts at this  
     446 * address. This case can happen when going back and forth to write collection 
     447 * objects to a Coordblock and is documented in bug 1657. 
     448 * 
    436449 * Returns 0 if succesful or -1 if an error happened, in which case  
    437450 * CPLError() will have been called. 
    438451 **********************************************************************/ 
    439452int     TABRawBinBlock::GotoByteInFile(int nOffset,  
    440                                        GBool bForceReadFromFile /*=FALSE*/) 
     453                                       GBool bForceReadFromFile /*=FALSE*/, 
     454                                       GBool bOffsetIsEndOfData /*=FALSE*/) 
    441455{ 
    442456    int nNewBlockPtr; 
     
    480494        // CommitToFile() should only be called only if something changed. 
    481495        // 
    482         if ( (nOffset<m_nFileOffset || nOffset>=m_nFileOffset+m_nBlockSize) && 
    483              (CommitToFile() != 0 || 
    484               (!bForceReadFromFile &&  
    485                InitNewBlock(m_fp, m_nBlockSize, nNewBlockPtr) != 0) || 
    486               (bForceReadFromFile && 
    487                ReadFromFile(m_fp, nNewBlockPtr, m_nBlockSize) != 0) )  ) 
     496        if (bOffsetIsEndOfData &&  nOffset%m_nBlockSize == 0) 
    488497        { 
    489             // Failed reading new block... error has already been reported. 
    490             return -1; 
     498            /* We're trying to go byte 512 of a block that's full of data. 
     499             * In this case it's okay to place the m_nCurPos at byte 512 
     500             * which is past the end of the block. 
     501             */ 
     502            if ( (nOffset < m_nFileOffset ||  
     503                  nOffset > m_nFileOffset+m_nBlockSize) && 
     504                 (CommitToFile() != 0 || 
     505                  (!bForceReadFromFile &&  
     506                   InitNewBlock(m_fp, m_nBlockSize, nNewBlockPtr) != 0) || 
     507                  (bForceReadFromFile && 
     508                   ReadFromFile(m_fp, nNewBlockPtr, m_nBlockSize) != 0) )  ) 
     509            { 
     510                // Failed reading new block... error has already been reported. 
     511                return -1; 
     512            } 
     513        } 
     514        else 
     515        { 
     516            if ( (nOffset < m_nFileOffset ||  
     517                  nOffset >= m_nFileOffset+m_nBlockSize) && 
     518                 (CommitToFile() != 0 || 
     519                  (!bForceReadFromFile &&  
     520                   InitNewBlock(m_fp, m_nBlockSize, nNewBlockPtr) != 0) || 
     521                  (bForceReadFromFile && 
     522                   ReadFromFile(m_fp, nNewBlockPtr, m_nBlockSize) != 0) )  ) 
     523            { 
     524                // Failed reading new block... error has already been reported. 
     525                return -1; 
     526            } 
    491527        } 
    492528    }