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:
@@ -64,6 +64,7 @@ ObjFileParser::ObjFileParser() :
|
||||
m_pModel(nullptr),
|
||||
m_uiLine(0),
|
||||
m_buffer(),
|
||||
mEnd(&m_buffer[Buffersize]),
|
||||
m_pIO(nullptr),
|
||||
m_progress(nullptr),
|
||||
m_originalObjFileName() {
|
||||
@@ -97,8 +98,6 @@ ObjFileParser::ObjFileParser(IOStreamBuffer<char> &streamBuffer, const std::stri
|
||||
parseFile(streamBuffer);
|
||||
}
|
||||
|
||||
ObjFileParser::~ObjFileParser() = default;
|
||||
|
||||
void ObjFileParser::setBuffer(std::vector<char> &buffer) {
|
||||
m_DataIt = buffer.begin();
|
||||
m_DataItEnd = buffer.end();
|
||||
@@ -121,6 +120,7 @@ void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
|
||||
while (streamBuffer.getNextDataLine(buffer, '\\')) {
|
||||
m_DataIt = buffer.begin();
|
||||
m_DataItEnd = buffer.end();
|
||||
mEnd = &buffer[buffer.size() - 1] + 1;
|
||||
|
||||
// Handle progress reporting
|
||||
const size_t filePos(streamBuffer.getFilePos());
|
||||
@@ -130,7 +130,7 @@ void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
|
||||
m_progress->UpdateFileRead(processed, progressTotal);
|
||||
}
|
||||
|
||||
// handle cstype section end (http://paulbourke.net/dataformats/obj/)
|
||||
// handle c-stype section end (http://paulbourke.net/dataformats/obj/)
|
||||
if (insideCstype) {
|
||||
switch (*m_DataIt) {
|
||||
case 'e': {
|
||||
@@ -301,18 +301,19 @@ size_t ObjFileParser::getNumComponentsInDataDefinition() {
|
||||
} else if (IsLineEnd(*tmp)) {
|
||||
end_of_definition = true;
|
||||
}
|
||||
if (!SkipSpaces(&tmp)) {
|
||||
if (!SkipSpaces(&tmp, mEnd)) {
|
||||
break;
|
||||
}
|
||||
const bool isNum(IsNumeric(*tmp) || isNanOrInf(tmp));
|
||||
SkipToken(tmp);
|
||||
SkipToken(tmp, mEnd);
|
||||
if (isNum) {
|
||||
++numComponents;
|
||||
}
|
||||
if (!SkipSpaces(&tmp)) {
|
||||
if (!SkipSpaces(&tmp, mEnd)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return numComponents;
|
||||
}
|
||||
|
||||
@@ -487,8 +488,9 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
|
||||
++iStep;
|
||||
}
|
||||
|
||||
if (iPos == 1 && !vt && vn)
|
||||
if (iPos == 1 && !vt && vn) {
|
||||
iPos = 2; // skip texture coords for normals if there are no tex coords
|
||||
}
|
||||
|
||||
if (iVal > 0) {
|
||||
// Store parsed index
|
||||
@@ -577,8 +579,9 @@ void ObjFileParser::getMaterialDesc() {
|
||||
// Get name
|
||||
std::string strName(pStart, &(*m_DataIt));
|
||||
strName = trim_whitespaces(strName);
|
||||
if (strName.empty())
|
||||
if (strName.empty()) {
|
||||
skip = true;
|
||||
}
|
||||
|
||||
// If the current mesh has the same material, we simply ignore that 'usemtl' command
|
||||
// There is no need to create another object or even mesh here
|
||||
|
||||
Reference in New Issue
Block a user