Fix import of binary STL files in double-precision builds
When ASSIMP_DOUBLE_PRECISION is used, the STL loader attempts to read 8-byte double vertex and normal values from the STL file. STL files are written using 4-byte floats, however, and the import will read past the end of the buffer, and possibly crash.pull/1827/head
parent
6173ac6cee
commit
05cf8bfb2e
|
@ -449,26 +449,29 @@ bool STLImporter::LoadBinaryFile()
|
||||||
aiVector3D *vp = pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
aiVector3D *vp = pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
||||||
aiVector3D *vn = pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
aiVector3D *vn = pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||||
|
|
||||||
|
typedef aiVector3t<float> aiVector3F;
|
||||||
|
aiVector3F* theVec;
|
||||||
|
|
||||||
for ( unsigned int i = 0; i < pMesh->mNumFaces; ++i ) {
|
for ( unsigned int i = 0; i < pMesh->mNumFaces; ++i ) {
|
||||||
// NOTE: Blender sometimes writes empty normals ... this is not
|
// NOTE: Blender sometimes writes empty normals ... this is not
|
||||||
// our fault ... the RemoveInvalidData helper step should fix that
|
// our fault ... the RemoveInvalidData helper step should fix that
|
||||||
::memcpy( vn, sz, sizeof( aiVector3D ) );
|
|
||||||
sz += sizeof(aiVector3D);
|
|
||||||
*(vn+1) = *vn;
|
|
||||||
*(vn+2) = *vn;
|
|
||||||
vn += 3;
|
|
||||||
|
|
||||||
::memcpy( vp, sz, sizeof( aiVector3D ) );
|
// There's one normal for the face in the STL; use it three times
|
||||||
++vp;
|
// for vertex normals
|
||||||
sz += sizeof(aiVector3D);
|
theVec = (aiVector3F*) sz;
|
||||||
|
*vn++ = *theVec;
|
||||||
|
*vn++ = *theVec;
|
||||||
|
*vn++ = *theVec++;
|
||||||
|
|
||||||
::memcpy( vp, sz, sizeof( aiVector3D ) );
|
// vertex 1
|
||||||
++vp;
|
*vp++ = *theVec++;
|
||||||
sz += sizeof(aiVector3D);
|
|
||||||
|
|
||||||
::memcpy( vp, sz, sizeof( aiVector3D ) );
|
// vertex 2
|
||||||
++vp;
|
*vp++ = *theVec++;
|
||||||
sz += sizeof(aiVector3D);
|
|
||||||
|
// vertex 3
|
||||||
|
*vp++ = *theVec;
|
||||||
|
sz += 4 * sizeof aiVector3F;
|
||||||
|
|
||||||
uint16_t color = *((uint16_t*)sz);
|
uint16_t color = *((uint16_t*)sz);
|
||||||
sz += 2;
|
sz += 2;
|
||||||
|
|
Loading…
Reference in New Issue