fix stl importer for malformed file
This commit is contained in:
parent
290ac7a027
commit
1ec2d65a58
|
@ -106,7 +106,7 @@ static bool IsSTLColored(const char * filename, bool &coloredFlag, bool &magicsM
|
||||||
coloredFlag=false;
|
coloredFlag=false;
|
||||||
magicsMode=false;
|
magicsMode=false;
|
||||||
bool binaryFlag;
|
bool binaryFlag;
|
||||||
if(IsSTLBinary(filename,binaryFlag)==false)
|
if(IsSTLMalformed(filename,binaryFlag)==false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(binaryFlag==false)
|
if(binaryFlag==false)
|
||||||
|
@ -144,11 +144,12 @@ static bool IsSTLColored(const char * filename, bool &coloredFlag, bool &magicsM
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to guess if a stl is in binary format
|
/*
|
||||||
*
|
|
||||||
* return false in case of malformed files
|
* return false in case of malformed files
|
||||||
|
* Try to guess if a stl is in binary format, and sets
|
||||||
|
* the binaryFlag accordingly
|
||||||
*/
|
*/
|
||||||
static bool IsSTLBinary(const char * filename, bool &binaryFlag)
|
static bool IsSTLMalformed(const char * filename, bool &binaryFlag)
|
||||||
{
|
{
|
||||||
binaryFlag=false;
|
binaryFlag=false;
|
||||||
FILE *fp = fopen(filename, "rb");
|
FILE *fp = fopen(filename, "rb");
|
||||||
|
@ -157,8 +158,10 @@ static bool IsSTLBinary(const char * filename, bool &binaryFlag)
|
||||||
std::size_t file_size = ftell(fp);
|
std::size_t file_size = ftell(fp);
|
||||||
unsigned int facenum;
|
unsigned int facenum;
|
||||||
/* Check for binary or ASCII file */
|
/* Check for binary or ASCII file */
|
||||||
fseek(fp, STL_LABEL_SIZE, SEEK_SET);
|
int ret = fseek(fp, STL_LABEL_SIZE, SEEK_SET);
|
||||||
fread(&facenum, sizeof(unsigned int), 1, fp);
|
if (ret != 0) return false;
|
||||||
|
ret = fread(&facenum, sizeof(unsigned int), 1, fp);
|
||||||
|
if (ret != 1) return false;
|
||||||
|
|
||||||
std::size_t expected_file_size=STL_LABEL_SIZE + 4 + (sizeof(short)+sizeof(STLFacet) )*facenum ;
|
std::size_t expected_file_size=STL_LABEL_SIZE + 4 + (sizeof(short)+sizeof(STLFacet) )*facenum ;
|
||||||
if(file_size == expected_file_size)
|
if(file_size == expected_file_size)
|
||||||
|
@ -197,7 +200,7 @@ static int Open( OpenMeshType &m, const char * filename, int &loadMask, CallBack
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
loadMask |= Mask::IOM_VERTCOORD | Mask::IOM_FACEINDEX;
|
loadMask |= Mask::IOM_VERTCOORD | Mask::IOM_FACEINDEX;
|
||||||
bool binaryFlag;
|
bool binaryFlag;
|
||||||
if(!IsSTLBinary(filename,binaryFlag))
|
if(!IsSTLMalformed(filename,binaryFlag))
|
||||||
return E_MALFORMED;
|
return E_MALFORMED;
|
||||||
|
|
||||||
if(binaryFlag) return OpenBinary(m,filename,loadMask,cb);
|
if(binaryFlag) return OpenBinary(m,filename,loadMask,cb);
|
||||||
|
|
Loading…
Reference in New Issue