Add bounds checks to the parsing utilities. (#5421)
* Add bounds checks to the parsing utilities. * Fix merge conflicts in ACLoader. * Fix loaders * Fix unittest of AC-Loader. * Remove dead code. * Md5Parser fixes * Fix md5-parsing * Fix Merge conflict * Fix merge conflicts. * Md5: Fix warning: missing return statement.
This commit is contained in:
@@ -250,7 +250,9 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
|
||||
};
|
||||
|
||||
// We know what format buffer is, collect numbers
|
||||
ParseBufferVertices(verticesNode.text().get(), vertexFormat,
|
||||
std::string v = verticesNode.text().get();
|
||||
const char *end = v.c_str() + v.size();
|
||||
ParseBufferVertices(v.c_str(), end, vertexFormat,
|
||||
curVertices, curNormals,
|
||||
curTangents, curBitangents,
|
||||
curUVs, curUV2s, curColors, useColors);
|
||||
@@ -329,8 +331,9 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
|
||||
|
||||
// NOTE this might explode for UTF-16 and wchars
|
||||
const char *sz = indicesNode.text().get();
|
||||
const char *end = sz + std::strlen(sz) + 1;
|
||||
// For each index loop over aiMesh faces
|
||||
while (SkipSpacesAndLineEnd(&sz)) {
|
||||
while (SkipSpacesAndLineEnd(&sz, end)) {
|
||||
if (curFace >= faceEnd) {
|
||||
ASSIMP_LOG_ERROR("IRRMESH: Too many indices");
|
||||
break;
|
||||
@@ -354,12 +357,18 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
|
||||
|
||||
// Copy over data to aiMesh
|
||||
*pcV++ = curVertices[idx];
|
||||
if (pcN) *pcN++ = curNormals[idx];
|
||||
if (pcT) *pcT++ = curTangents[idx];
|
||||
if (pcB) *pcB++ = curBitangents[idx];
|
||||
if (pcC0) *pcC0++ = curColors[idx];
|
||||
if (pcT0) *pcT0++ = curUVs[idx];
|
||||
if (pcT1) *pcT1++ = curUV2s[idx];
|
||||
if (pcN)
|
||||
*pcN++ = curNormals[idx];
|
||||
if (pcT)
|
||||
*pcT++ = curTangents[idx];
|
||||
if (pcB)
|
||||
*pcB++ = curBitangents[idx];
|
||||
if (pcC0)
|
||||
*pcC0++ = curColors[idx];
|
||||
if (pcT0)
|
||||
*pcT0++ = curUVs[idx];
|
||||
if (pcT1)
|
||||
*pcT1++ = curUV2s[idx];
|
||||
|
||||
// start new face
|
||||
if (++curIdx == 3) {
|
||||
@@ -421,37 +430,37 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
|
||||
};
|
||||
}
|
||||
|
||||
void IRRMeshImporter::ParseBufferVertices(const char *sz, VertexFormat vertexFormat,
|
||||
void IRRMeshImporter::ParseBufferVertices(const char *sz, const char *end, VertexFormat vertexFormat,
|
||||
std::vector<aiVector3D> &vertices, std::vector<aiVector3D> &normals,
|
||||
std::vector<aiVector3D> &tangents, std::vector<aiVector3D> &bitangents,
|
||||
std::vector<aiVector3D> &UVs, std::vector<aiVector3D> &UV2s,
|
||||
std::vector<aiColor4D> &colors, bool &useColors) {
|
||||
// read vertices
|
||||
do {
|
||||
SkipSpacesAndLineEnd(&sz);
|
||||
SkipSpacesAndLineEnd(&sz, end);
|
||||
aiVector3D temp;
|
||||
aiColor4D c;
|
||||
|
||||
// Read the vertex position
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.x);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.y);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.z);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
vertices.push_back(temp);
|
||||
|
||||
// Read the vertex normals
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.x);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.y);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.z);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
normals.push_back(temp);
|
||||
|
||||
// read the vertex colors
|
||||
@@ -463,14 +472,14 @@ void IRRMeshImporter::ParseBufferVertices(const char *sz, VertexFormat vertexFor
|
||||
useColors = true;
|
||||
|
||||
colors.push_back(c);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
|
||||
// read the first UV coordinate set
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.x);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.y);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
temp.z = 0.f;
|
||||
temp.y = 1.f - temp.y; // DX to OGL
|
||||
UVs.push_back(temp);
|
||||
@@ -480,7 +489,7 @@ void IRRMeshImporter::ParseBufferVertices(const char *sz, VertexFormat vertexFor
|
||||
// read the (optional) second UV coordinate set
|
||||
if (vertexFormat == VertexFormat::t2coord) {
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.x);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.y);
|
||||
temp.y = 1.f - temp.y; // DX to OGL
|
||||
@@ -490,33 +499,32 @@ void IRRMeshImporter::ParseBufferVertices(const char *sz, VertexFormat vertexFor
|
||||
else if (vertexFormat == VertexFormat::tangent) {
|
||||
// tangents
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.x);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.z);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.y);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
temp.y *= -1.0f;
|
||||
tangents.push_back(temp);
|
||||
|
||||
// bitangents
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.x);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.z);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.y);
|
||||
SkipSpaces(&sz);
|
||||
SkipSpaces(&sz, end);
|
||||
temp.y *= -1.0f;
|
||||
bitangents.push_back(temp);
|
||||
}
|
||||
} while (SkipLine(&sz));
|
||||
/* IMPORTANT: We assume that each vertex is specified in one
|
||||
line. So we can skip the rest of the line - unknown vertex
|
||||
elements are ignored.
|
||||
*/
|
||||
} while (SkipLine(&sz, end));
|
||||
// IMPORTANT: We assume that each vertex is specified in one
|
||||
// line. So we can skip the rest of the line - unknown vertex
|
||||
// elements are ignored.
|
||||
}
|
||||
|
||||
#endif // !! ASSIMP_BUILD_NO_IRRMESH_IMPORTER
|
||||
|
||||
Reference in New Issue
Block a user