Răsfoiți Sursa

Merge commit 'acca16c82fb9fa37c40475a423e979e9c7aa0d5a' into contrib

Léo Terziman 11 ani în urmă
părinte
comite
d080eb493e
3 a modificat fișierele cu 14 adăugiri și 2 ștergeri
  1. 2 0
      code/3DSLoader.cpp
  2. 8 1
      code/DefaultIOStream.cpp
  3. 4 1
      code/SortByPTypeProcess.cpp

+ 2 - 0
code/3DSLoader.cpp

@@ -79,6 +79,8 @@ static const aiImporterDesc desc = {
 	Discreet3DS::Chunk chunk;                                            \
 	ReadChunk(&chunk);                                                   \
 	int chunkSize = chunk.Size-sizeof(Discreet3DS::Chunk);	             \
+    if(chunkSize <= 0)                                                   \
+        continue;                                                        \
 	const int oldReadLimit = stream->GetReadLimit();                     \
 	stream->SetReadLimit(stream->GetCurrentPos() + chunkSize);           \
 	

+ 8 - 1
code/DefaultIOStream.cpp

@@ -110,7 +110,14 @@ size_t DefaultIOStream::FileSize() const
 	
 	if (SIZE_MAX == cachedSize) {
 
-		// TODO: Is that really faster if we're already owning a handle to the file?
+        // Although fseek/ftell would allow us to reuse the exising file handle here,
+        // it is generally unsafe because:
+        //  - For binary streams, it is not technically well-defined
+        //  - For text files the results are meaningless
+        // That's why we use the safer variant fstat here.
+        //
+        // See here for details:
+        // https://www.securecoding.cert.org/confluence/display/seccode/FIO19-C.+Do+not+use+fseek()+and+ftell()+to+compute+the+size+of+a+regular+file
 #if defined _WIN32 && !defined __GNUC__
 		struct __stat64 fileStat; 
 		int err = _stat64(  mFilename.c_str(), &fileStat ); 

+ 4 - 1
code/SortByPTypeProcess.cpp

@@ -151,7 +151,7 @@ void SortByPTypeProcess::Execute( aiScene* pScene)
 	std::vector<unsigned int>::iterator meshIdx = replaceMeshIndex.begin();
 	for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
 	{
-		aiMesh* mesh = pScene->mMeshes[i];
+		aiMesh* const mesh = pScene->mMeshes[i];
 		ai_assert(0 != mesh->mPrimitiveTypes);
 
 		// if there's just one primitive type in the mesh there's nothing to do for us
@@ -367,6 +367,9 @@ void SortByPTypeProcess::Execute( aiScene* pScene)
 
 		// delete the input mesh
 		delete mesh;
+
+        // avoid invalid pointer
+        pScene->mMeshes[i] = NULL;
 	}
 
 	if (outMeshes.empty())