diff --git a/gdal/ogr/ogrsf_frmts/cad/libopencad/cadtables.cpp b/gdal/ogr/ogrsf_frmts/cad/libopencad/cadtables.cpp index 6f3e5dd5d254..d3d0d1643d70 100644 --- a/gdal/ogr/ogrsf_frmts/cad/libopencad/cadtables.cpp +++ b/gdal/ogr/ogrsf_frmts/cad/libopencad/cadtables.cpp @@ -127,35 +127,22 @@ int CADTables::ReadLayersTable( CADFile * const pCADFile, long dLayerControlHand unique_ptr spEntityObj( static_cast( pCADFile->GetObject( dCurrentEntHandle, true )) ); - if( dCurrentEntHandle == dLastEntHandle ) + if( spEntityObj == nullptr ) { - if( nullptr != spEntityObj ) - FillLayer( spEntityObj.get() ); - else - { -#ifdef _DEBUG - assert( 0 ); -#endif //_DEBUG - } + DebugMsg( "Entity object is null\n" ); break; - } - - /* This check may look excessive, but if something goes wrong way - - * some part of geometries will be parsed. */ - if( spEntityObj != nullptr ) + } else if ( dCurrentEntHandle == dLastEntHandle ) { FillLayer( spEntityObj.get() ); - - if( spEntityObj->stCed.bNoLinks ) - ++dCurrentEntHandle; - else - dCurrentEntHandle = spEntityObj->stChed.hNextEntity.getAsLong( spEntityObj->stCed.hObjectHandle ); - } else - { -#ifdef _DEBUG - assert( 0 ); -#endif //_DEBUG + break; } + + FillLayer( spEntityObj.get() ); + + if( spEntityObj->stCed.bNoLinks ) + ++dCurrentEntHandle; + else + dCurrentEntHandle = spEntityObj->stChed.hNextEntity.getAsLong( spEntityObj->stCed.hObjectHandle ); } DebugMsg( "Readed aLayers using LayerControl object count: %d\n", diff --git a/gdal/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp b/gdal/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp index bd4b4fbefbb2..89d6042419b2 100644 --- a/gdal/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp +++ b/gdal/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp @@ -61,6 +61,26 @@ using namespace std; +static unsigned short validateEntityCRC( const char * pabyInput, + unsigned int dObjectSize, size_t & nBitOffsetFromStart, + const char * entityName = "ENTITY" ) +{ + const int size = dObjectSize - 2; + + nBitOffsetFromStart = size * 8; + const unsigned short nCRC = ReadRAWSHORT( pabyInput, nBitOffsetFromStart ); + + const unsigned short initial = 0xC0C1; + const unsigned short nCalculated = CalculateCRC8( initial, pabyInput, size ); + + if( nCRC != nCalculated ) + { + DebugMsg( "Invalid CRC for %s object\n", entityName ); + DebugMsg( "CRC read:0x%X calculated:0x%X\n", nCRC, nCalculated ); + } + return nCRC; +} + int DWGFileR2000::ReadHeader( OpenOptions eOptions ) { char buffer[255]; @@ -82,9 +102,13 @@ int DWGFileR2000::ReadHeader( OpenOptions eOptions ) DebugMsg( "Header variables section length: %d\n", static_cast(dHeaderVarsSectionLength) ); - size_t nBitOffsetFromStart = 0; - pabyBuf = new char[dHeaderVarsSectionLength + 4]; - pFileIO->Read( pabyBuf, dHeaderVarsSectionLength + 2 ); + // crc is calculated on (long+data) buffer + // buffer size: long (4 bytes) + data (variable) + crc (2 bytes) + pabyBuf = new char[4 + dHeaderVarsSectionLength + 2]; + pFileIO->Seek( -4L, CADFileIO::SeekOrigin::CUR ); + pFileIO->Read( pabyBuf, 4 + dHeaderVarsSectionLength + 2 ); + + size_t nBitOffsetFromStart = 32; if( eOptions == OpenOptions::READ_ALL ) { @@ -618,22 +642,28 @@ int DWGFileR2000::ReadHeader( OpenOptions eOptions ) SkipBITSHORT( pabyBuf, nBitOffsetFromStart ); } - /*short nCRC =*/ ReadRAWSHORT( pabyBuf, nBitOffsetFromStart ); -#ifdef FIXME - unsigned short initial = 0xC0C1; - /*short calculated_crc = */ CalculateCRC8( initial, pabyBuf, - static_cast(dHeaderVarsSectionLength) ); // TODO: CRC is calculated wrong every time. -#endif + // byte align data + nBitOffsetFromStart = (4 + dHeaderVarsSectionLength) * 8; int returnCode = CADErrorCodes::SUCCESS; - pFileIO->Read( pabyBuf, DWGConstants::SentinelLength ); - if( memcmp( pabyBuf, DWGConstants::HeaderVariablesEnd, - DWGConstants::SentinelLength ) ) - { - DebugMsg( "File is corrupted (HEADERVARS section ending sentinel " - "doesn't match.)" ); + unsigned short nCRC = ReadRAWSHORT( pabyBuf, nBitOffsetFromStart ); + unsigned short initial = 0xC0C1; + unsigned short nCalculated = CalculateCRC8( + initial, pabyBuf, static_cast(4 + dHeaderVarsSectionLength) ); + if( nCRC != nCalculated ) + { + DebugMsg( "File is corrupted (HEADERVARS section CRC doesn't match)\n" ); returnCode = CADErrorCodes::HEADER_SECTION_READ_FAILED; + } else + { + pFileIO->Read( pabyBuf, DWGConstants::SentinelLength ); + if( memcmp( pabyBuf, DWGConstants::HeaderVariablesEnd, + DWGConstants::SentinelLength ) ) + { + DebugMsg( "File is corrupted (HEADERVARS section ending sentinel doesn't match)\n" ); + returnCode = CADErrorCodes::HEADER_SECTION_READ_FAILED; + } } delete[] pabyBuf; @@ -647,7 +677,6 @@ int DWGFileR2000::ReadClasses( enum OpenOptions eOptions ) char * pabySectionContent; char buffer[255]; size_t dSectionSize = 0; - size_t nBitOffsetFromStart = 0; pFileIO->Seek( sectionLocatorRecords[1].dSeeker, CADFileIO::SeekOrigin::BEG ); @@ -655,8 +684,8 @@ int DWGFileR2000::ReadClasses( enum OpenOptions eOptions ) if( memcmp( buffer, DWGConstants::DSClassesStart, DWGConstants::SentinelLength ) ) { - std::cerr << "File is corrupted (wrong pointer to CLASSES section," - "or CLASSES starting sentinel corrupted.)\n"; + DebugMsg( "File is corrupted (wrong pointer to CLASSES section," + " or CLASSES starting sentinel corrupted.)\n" ); return CADErrorCodes::CLASSES_SECTION_READ_FAILED; } @@ -665,8 +694,11 @@ int DWGFileR2000::ReadClasses( enum OpenOptions eOptions ) DebugMsg( "Classes section length: %d\n", static_cast(dSectionSize) ); - pabySectionContent = new char[dSectionSize + 4]; - pFileIO->Read( pabySectionContent, dSectionSize ); + pabySectionContent = new char[4 + dSectionSize + 2]; + pFileIO->Seek( -4L, CADFileIO::SeekOrigin::CUR ); + pFileIO->Read( pabySectionContent, 4 + dSectionSize + 2 ); + + size_t nBitOffsetFromStart = 32; while( ( nBitOffsetFromStart / 8 + 1 ) < dSectionSize ) { @@ -682,16 +714,26 @@ int DWGFileR2000::ReadClasses( enum OpenOptions eOptions ) oClasses.addClass( stClass ); } + nBitOffsetFromStart = (4 + dSectionSize) * 8; + + unsigned short nCRC = ReadRAWSHORT( pabySectionContent, nBitOffsetFromStart ); + unsigned short initial = 0xC0C1; + unsigned short nCalculated = CalculateCRC8( + initial, pabySectionContent, static_cast(4 + dSectionSize) ); + delete[] pabySectionContent; - pFileIO->Read( buffer, 2 ); // CLASSES CRC!. TODO: add CRC computing & checking feature. + if( nCRC != nCalculated ) + { + DebugMsg( "File is corrupted (CLASSES section CRC doesn't match)\n" ); + return CADErrorCodes::CLASSES_SECTION_READ_FAILED; + } pFileIO->Read( buffer, DWGConstants::SentinelLength ); if( memcmp( buffer, DWGConstants::DSClassesEnd, DWGConstants::SentinelLength ) ) { - std::cerr << "File is corrupted (CLASSES section ending sentinel " - "doesn't match.)\n"; + DebugMsg( "File is corrupted (CLASSES section ending sentinel doesn't match)\n" ); return CADErrorCodes::CLASSES_SECTION_READ_FAILED; } } @@ -727,13 +769,15 @@ int DWGFileR2000::CreateFileMap() if( dSectionSize == 2 ) break; // last section is empty. - char * pabySectionContent = new char[dSectionSize + 4]; - size_t nBitOffsetFromStart = 0; + char * pabySectionContent = new char[2 + dSectionSize]; size_t nRecordsInSection = 0; // read section data - pFileIO->Read( pabySectionContent, dSectionSize ); - unsigned int dSectionBitSize = (dSectionSize * 8) - 128; // 8 + 8*7 + pFileIO->Seek( -2L, CADFileIO::SeekOrigin::CUR ); + pFileIO->Read( pabySectionContent, 2 + dSectionSize ); + unsigned int dSectionBitSize = (2 + dSectionSize - 2) * 8; + + size_t nBitOffsetFromStart = 16; while( nBitOffsetFromStart < dSectionBitSize ) { @@ -757,12 +801,23 @@ int DWGFileR2000::CreateFileMap() ++nRecordsInSection; } - /* Unused - dSectionCRC = */ReadRAWSHORT( pabySectionContent, nBitOffsetFromStart );/* + // byte align data + nBitOffsetFromStart = (2 + dSectionSize - 2) * 8; + + unsigned short dSectionCRC = ReadRAWSHORT( pabySectionContent, nBitOffsetFromStart ); SwapEndianness (dSectionCRC, sizeof (dSectionCRC)); - */ + + unsigned short initial = 0xC0C1; + unsigned short nCalculated = CalculateCRC8( + initial, pabySectionContent, static_cast(2 + dSectionSize - 2) ); delete[] pabySectionContent; + + if( dSectionCRC != nCalculated ) + { + DebugMsg( "File is corrupted (OBJECTMAP section CRC doesn't match)\n" ); + return CADErrorCodes::OBJECTS_SECTION_READ_FAILED; + } } return CADErrorCodes::SUCCESS; @@ -776,6 +831,10 @@ CADObject * DWGFileR2000::GetObject( long dHandle, bool bHandlesOnly ) pFileIO->Read( pabyObjectSize, 8 ); unsigned int dObjectSize = ReadMSHORT( pabyObjectSize, nBitOffsetFromStart ); + // FIXME: limit object size to 64kB + if( dObjectSize > 65536 ) + return nullptr; + // And read whole data chunk into memory for future parsing. // + nBitOffsetFromStart/8 + 2 is because dObjectSize doesn't cover CRC and itself. size_t nSectionSize = dObjectSize + nBitOffsetFromStart / 8 + 2; @@ -788,6 +847,9 @@ CADObject * DWGFileR2000::GetObject( long dHandle, bool bHandlesOnly ) dObjectSize = ReadMSHORT( pabySectionContent, nBitOffsetFromStart ); short dObjectType = ReadBITSHORT( pabySectionContent, nBitOffsetFromStart ); + // FIXME: needed for CRC validation + dObjectSize = (unsigned int) nSectionSize; + if( dObjectType >= 500 ) { CADClass cadClass = oClasses.getClassByNum( dObjectType ); @@ -1412,7 +1474,7 @@ CADGeometry * DWGFileR2000::GetGeometry( size_t iLayerIndex, long dHandle, long case CADObject::VERTEX_MESH: case CADObject::VERTEX_PFACE_FACE: default: - std::cerr << "Asked geometry has unsupported type." << endl; + DebugMsg( "Asked geometry has unsupported type." ); poGeometry = new CADUnknown(); break; } @@ -1618,14 +1680,7 @@ CADBlockObject * DWGFileR2000::getBlock( long dObjectSize, const CADCommonED& st fillCommonEntityHandleData( pBlock, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - pBlock->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + pBlock->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart, "BLOCK" ) ); return pBlock; } @@ -1656,14 +1711,7 @@ CADEllipseObject * DWGFileR2000::getEllipse( long dObjectSize, const CADCommonED fillCommonEntityHandleData( ellipse, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - ellipse->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + ellipse->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart, "ELLIPSE" ) ); return ellipse; } @@ -1701,14 +1749,7 @@ CADSolidObject * DWGFileR2000::getSolid( long dObjectSize, const CADCommonED& st fillCommonEntityHandleData( solid, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - solid->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + solid->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart, "SOLID" ) ); return solid; } @@ -1741,14 +1782,7 @@ CADPointObject * DWGFileR2000::getPoint( long dObjectSize, const CADCommonED& st fillCommonEntityHandleData( point, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - point->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + point->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return point; } @@ -1771,14 +1805,7 @@ CADPolyline3DObject * DWGFileR2000::getPolyLine3D( long dObjectSize, const CADCo polyline->hSeqend = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - polyline->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + polyline->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return polyline; } @@ -1800,14 +1827,7 @@ CADRayObject * DWGFileR2000::getRay( long dObjectSize, const CADCommonED& stComm fillCommonEntityHandleData( ray, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - ray->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + ray->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return ray; } @@ -1829,14 +1849,7 @@ CADXLineObject * DWGFileR2000::getXLine( long dObjectSize, const CADCommonED& st fillCommonEntityHandleData( xline, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - xline->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + xline->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return xline; } @@ -1880,14 +1893,7 @@ CADLineObject * DWGFileR2000::getLine( long dObjectSize, const CADCommonED& stCo fillCommonEntityHandleData( line, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - line->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + line->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return line; } @@ -1952,14 +1958,7 @@ CADTextObject * DWGFileR2000::getText( long dObjectSize, const CADCommonED& stCo text->hStyle = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - text->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + text->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return text; } @@ -1979,14 +1978,7 @@ CADVertex3DObject * DWGFileR2000::getVertex3D( long dObjectSize, const CADCommon fillCommonEntityHandleData( vertex, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - vertex->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + vertex->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return vertex; } @@ -2015,14 +2007,7 @@ CADCircleObject * DWGFileR2000::getCircle( long dObjectSize, const CADCommonED& fillCommonEntityHandleData( circle, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - circle->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + circle->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return circle; } @@ -2036,14 +2021,7 @@ CADEndblkObject * DWGFileR2000::getEndBlock( long dObjectSize, const CADCommonED fillCommonEntityHandleData( endblk, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - endblk->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + endblk->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return endblk; } @@ -2083,14 +2061,7 @@ CADPolyline2DObject * DWGFileR2000::getPolyline2D( long dObjectSize, const CADCo polyline->hSeqend = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - polyline->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + polyline->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return polyline; } @@ -2154,14 +2125,7 @@ CADAttribObject * DWGFileR2000::getAttributes( long dObjectSize, const CADCommon attrib->hStyle = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - attrib->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + attrib->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return attrib; } @@ -2228,14 +2192,7 @@ CADAttdefObject * DWGFileR2000::getAttributesDefn( long dObjectSize, const CADCo attdef->hStyle = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - attdef->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + attdef->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return attdef; } @@ -2315,14 +2272,7 @@ CADLWPolylineObject * DWGFileR2000::getLWPolyLine( long dObjectSize, const CADCo fillCommonEntityHandleData( polyline, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - polyline->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + polyline->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return polyline; } @@ -2354,13 +2304,7 @@ CADArcObject * DWGFileR2000::getArc( long dObjectSize, const CADCommonED& stComm fillCommonEntityHandleData( arc, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - arc->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + arc->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return arc; } @@ -2423,14 +2367,7 @@ CADSplineObject * DWGFileR2000::getSpline( long dObjectSize, const CADCommonED& fillCommonEntityHandleData( spline, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - spline->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + spline->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return spline; } @@ -2448,13 +2385,7 @@ CADEntityObject * DWGFileR2000::getEntity( int dObjectType, long dObjectSize, co fillCommonEntityHandleData( entity, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - entity->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + entity->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return entity; } @@ -2502,13 +2433,7 @@ CADInsertObject * DWGFileR2000::getInsert( int dObjectType, long dObjectSize, co insert->hSeqend = ReadHANDLE( pabyInput, nBitOffsetFromStart ); } - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - insert->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + insert->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return insert; } @@ -2559,14 +2484,7 @@ CADDictionaryObject * DWGFileR2000::getDictionary( long dObjectSize, const char for( long i = 0; i < dictionary->nNumItems; ++i ) dictionary->hItemHandles.push_back( ReadHANDLE( pabyInput, nBitOffsetFromStart ) ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - dictionary->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif // _DEBUG + dictionary->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return dictionary; } @@ -2624,14 +2542,7 @@ CADLayerObject * DWGFileR2000::getLayerObject( long dObjectSize, const char * pa */ // layer->hUnknownHandle = ReadHANDLE (pabySectionContent, nBitOffsetFromStart); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - layer->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + layer->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return layer; } @@ -2667,13 +2578,7 @@ CADLayerControlObject * DWGFileR2000::getLayerControl( long dObjectSize, const c for( long i = 0; i < layerControl->nNumEntries; ++i ) layerControl->hLayers.push_back( ReadHANDLE( pabyInput, nBitOffsetFromStart ) ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - layerControl->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + layerControl->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return layerControl; } @@ -2712,13 +2617,7 @@ CADBlockControlObject * DWGFileR2000::getBlockControl( long dObjectSize, const c blockControl->hBlocks.push_back( ReadHANDLE( pabyInput, nBitOffsetFromStart ) ); } - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - blockControl->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + blockControl->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return blockControl; } @@ -2789,13 +2688,7 @@ CADBlockHeaderObject * DWGFileR2000::getBlockHeader( long dObjectSize, const cha blockHeader->hInsertHandles.push_back( ReadHANDLE( pabyInput, nBitOffsetFromStart ) ); blockHeader->hLayout = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - blockHeader->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + blockHeader->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return blockHeader; } @@ -2832,14 +2725,7 @@ CADLineTypeControlObject * DWGFileR2000::getLineTypeControl( long dObjectSize, c for( long i = 0; i < ltypeControl->nNumEntries + 2; ++i ) ltypeControl->hLTypes.push_back( ReadHANDLE( pabyInput, nBitOffsetFromStart ) ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - ltypeControl->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + ltypeControl->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return ltypeControl; } @@ -2902,14 +2788,7 @@ CADLineTypeObject * DWGFileR2000::getLineType1( long dObjectSize, const char * p // TODO: shapefile for dash/shape (1 each). Does it mean that we have nNumDashes * 2 handles, or what? - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - ltype->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "[NOT IMPORTANT, CAUSE NOT IMPLEMENTATION NOT COMPLETED] " - "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + ltype->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return ltype; } @@ -2981,14 +2860,7 @@ CADMLineObject * DWGFileR2000::getMLine( long dObjectSize, const CADCommonED& st if( mline->stCed.bbPlotStyleFlags == 0x03 ) mline->stChed.hPlotStyle = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - mline->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + mline->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return mline; } @@ -3010,14 +2882,7 @@ CADPolylinePFaceObject * DWGFileR2000::getPolylinePFace( long dObjectSize, const polyline->hSeqend = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - polyline->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + polyline->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return polyline; } @@ -3073,14 +2938,7 @@ CADImageObject * DWGFileR2000::getImage( long dObjectSize, const CADCommonED& st image->hImageDef = ReadHANDLE( pabyInput, nBitOffsetFromStart ); image->hImageDefReactor = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - image->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + image->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return image; } @@ -3120,14 +2978,7 @@ CAD3DFaceObject * DWGFileR2000::get3DFace( long dObjectSize, const CADCommonED& fillCommonEntityHandleData( face, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - face->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif //_DEBUG + face->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return face; } @@ -3145,14 +2996,7 @@ CADVertexMeshObject * DWGFileR2000::getVertexMesh( long dObjectSize, const CADCo fillCommonEntityHandleData( vertex, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - vertex->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); - -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + vertex->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return vertex; } @@ -3170,13 +3014,7 @@ CADVertexPFaceObject * DWGFileR2000::getVertexPFace( long dObjectSize, const CAD fillCommonEntityHandleData( vertex, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); // padding bits to next byte boundary - vertex->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + vertex->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return vertex; } @@ -3210,13 +3048,7 @@ CADMTextObject * DWGFileR2000::getMText( long dObjectSize, const CADCommonED& st fillCommonEntityHandleData( text, pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - text->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + text->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return text; } @@ -3277,13 +3109,7 @@ CADDimensionObject * DWGFileR2000::getDimension( short dObjectType, long dObject dimension->hDimstyle = ReadHANDLE( pabyInput, nBitOffsetFromStart ); dimension->hAnonymousBlock = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - dimension->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + dimension->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return dimension; } @@ -3312,13 +3138,7 @@ CADDimensionObject * DWGFileR2000::getDimension( short dObjectType, long dObject dimension->hDimstyle = ReadHANDLE( pabyInput, nBitOffsetFromStart ); dimension->hAnonymousBlock = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - dimension->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + dimension->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return dimension; } @@ -3346,13 +3166,7 @@ CADDimensionObject * DWGFileR2000::getDimension( short dObjectType, long dObject dimension->hDimstyle = ReadHANDLE( pabyInput, nBitOffsetFromStart ); dimension->hAnonymousBlock = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - dimension->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + dimension->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return dimension; } @@ -3381,13 +3195,7 @@ CADDimensionObject * DWGFileR2000::getDimension( short dObjectType, long dObject dimension->hDimstyle = ReadHANDLE( pabyInput, nBitOffsetFromStart ); dimension->hAnonymousBlock = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - dimension->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + dimension->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return dimension; } @@ -3419,13 +3227,7 @@ CADDimensionObject * DWGFileR2000::getDimension( short dObjectType, long dObject dimension->hDimstyle = ReadHANDLE( pabyInput, nBitOffsetFromStart ); dimension->hAnonymousBlock = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - dimension->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + dimension->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return dimension; } @@ -3450,13 +3252,7 @@ CADDimensionObject * DWGFileR2000::getDimension( short dObjectType, long dObject dimension->hDimstyle = ReadHANDLE( pabyInput, nBitOffsetFromStart ); dimension->hAnonymousBlock = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - dimension->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + dimension->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return dimension; } @@ -3481,13 +3277,7 @@ CADDimensionObject * DWGFileR2000::getDimension( short dObjectType, long dObject dimension->hDimstyle = ReadHANDLE( pabyInput, nBitOffsetFromStart ); dimension->hAnonymousBlock = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - dimension->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + dimension->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return dimension; } } @@ -3538,13 +3328,7 @@ CADImageDefObject * DWGFileR2000::getImageDef( long dObjectSize, const char * pa imagedef->hXDictionary = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - imagedef->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + imagedef->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return imagedef; } @@ -3583,13 +3367,7 @@ CADImageDefReactorObject * DWGFileR2000::getImageDefReactor( long dObjectSize, c imagedefreactor->hXDictionary = ReadHANDLE( pabyInput, nBitOffsetFromStart ); - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - imagedefreactor->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( ( nBitOffsetFromStart / 8 ) != ( dObjectSize + 4 ) ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart / 8 - dObjectSize - 4 ) ); -#endif + imagedefreactor->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return imagedefreactor; } @@ -3665,13 +3443,7 @@ CADXRecordObject * DWGFileR2000::getXRecord( long dObjectSize, const char * paby xrecord->hObjIdHandles.push_back( ReadHANDLE( pabyInput, nBitOffsetFromStart ) ); } - nBitOffsetFromStart += 8 - ( nBitOffsetFromStart % 8 ); - xrecord->setCRC( ReadRAWSHORT( pabyInput, nBitOffsetFromStart ) ); -#ifdef _DEBUG - if( nBitOffsetFromStart != dObjectSizeBit ) - DebugMsg( "Assertion failed at %d in %s\nSize difference: %d\n", __LINE__, __FILE__, - ( nBitOffsetFromStart - dObjectSizeBit ) / 8 ); -#endif + xrecord->setCRC( validateEntityCRC( pabyInput, dObjectSize, nBitOffsetFromStart ) ); return xrecord; } diff --git a/gdal/ogr/ogrsf_frmts/cad/ogrcaddriver.cpp b/gdal/ogr/ogrsf_frmts/cad/ogrcaddriver.cpp index f72729645efe..a3e420342a47 100644 --- a/gdal/ogr/ogrsf_frmts/cad/ogrcaddriver.cpp +++ b/gdal/ogr/ogrsf_frmts/cad/ogrcaddriver.cpp @@ -150,18 +150,62 @@ void RegisterOGRCAD() CPLString CADRecode( const CPLString& sString, int CADEncoding ) { - switch( CADEncoding ) + const char* pszSource[] = { + /* 0 UNDEFINED */ "", + /* 1 ASCII */ "US-ASCII", + /* 2 8859_1 */ "ISO-8859-1", + /* 3 8859_2 */ "ISO-8859-2", + /* 4 UNDEFINED */ "", + /* 5 8859_4 */ "ISO-8859-4", + /* 6 8859_5 */ "ISO-8859-5", + /* 7 8859_6 */ "ISO-8859-6", + /* 8 8859_7 */ "ISO-8859-7", + /* 9 8859_8 */ "ISO-8859-8", + /* 10 8859_9 */ "ISO-8859-9", + /* 11 DOS437 */ "CP437", + /* 12 DOS850 */ "CP850", + /* 13 DOS852 */ "CP852", + /* 14 DOS855 */ "CP855", + /* 15 DOS857 */ "CP857", + /* 16 DOS860 */ "CP860", + /* 17 DOS861 */ "CP861", + /* 18 DOS863 */ "CP863", + /* 19 DOS864 */ "CP864", + /* 20 DOS865 */ "CP865", + /* 21 DOS869 */ "CP869", + /* 22 DOS932 */ "CP932", + /* 23 MACINTOSH */ "MACINTOSH", + /* 24 BIG5 */ "BIG5", + /* 25 KSC5601 */ "CP949", + /* 26 JOHAB */ "JOHAB", + /* 27 DOS866 */ "CP866", + /* 28 ANSI_1250 */ "CP1250", + /* 29 ANSI_1251 */ "CP1251", + /* 30 ANSI_1252 */ "CP1252", + /* 31 GB2312 */ "GB2312", + /* 32 ANSI_1253 */ "CP1253", + /* 33 ANSI_1254 */ "CP1254", + /* 34 ANSI_1255 */ "CP1255", + /* 35 ANSI_1256 */ "CP1256", + /* 36 ANSI_1257 */ "CP1257", + /* 37 ANSI_874 */ "CP874", + /* 38 ANSI_932 */ "CP932", + /* 39 ANSI_936 */ "CP936", + /* 40 ANSI_949 */ "CP949", + /* 41 ANSI_950 */ "CP950", + /* 42 ANSI_1361 */ "CP1361", + /* 43 ANSI_1200 */ "UTF-16", + /* 44 ANSI_1258 */ "CP1258" + }; + if( CADEncoding > 0 && CADEncoding < 45 && CADEncoding != 4 ) { - case 29: - { - char* pszRecoded = CPLRecode( sString, "CP1251", CPL_ENC_UTF8 ); - CPLString soRecoded(pszRecoded); - CPLFree(pszRecoded); - return soRecoded; - } - default: - CPLError( CE_Failure, CPLE_NotSupported, - "CADRecode() function does not support provided CADEncoding." ); - return CPLString(""); + char* pszRecoded = CPLRecode( sString, pszSource[CADEncoding], CPL_ENC_UTF8 ); + CPLString soRecoded(pszRecoded); + CPLFree(pszRecoded); + return soRecoded; } + + CPLError( CE_Failure, CPLE_NotSupported, + "CADRecode() function does not support provided CADEncoding." ); + return CPLString(""); }