ソースを参照

Fix memory corruption when 3DS file has more smoothing groups than faces

Turo Lamminen 10 年 前
コミット
2f0675ac53
1 ファイル変更3 行追加0 行削除
  1. 3 0
      code/3DSLoader.cpp

+ 3 - 0
code/3DSLoader.cpp

@@ -948,6 +948,9 @@ void Discreet3DSImporter::ParseFaceChunk()
 		// This is the list of smoothing groups - a bitfield for every face. 
 		// This is the list of smoothing groups - a bitfield for every face. 
 		// Up to 32 smoothing groups assigned to a single face.
 		// Up to 32 smoothing groups assigned to a single face.
 		unsigned int num = chunkSize/4, m = 0;
 		unsigned int num = chunkSize/4, m = 0;
+		if (num > mMesh.mFaces.size())	{
+			throw DeadlyImportError("3DS: More smoothing groups than faces");
+		}
 		for (std::vector<D3DS::Face>::iterator i =  mMesh.mFaces.begin(); m != num;++i, ++m)	{
 		for (std::vector<D3DS::Face>::iterator i =  mMesh.mFaces.begin(); m != num;++i, ++m)	{
 			// nth bit is set for nth smoothing group
 			// nth bit is set for nth smoothing group
 			(*i).iSmoothGroup = stream->GetI4();
 			(*i).iSmoothGroup = stream->GetI4();