Skip to content

Commit

Permalink
Merge branch 'assimp:master' into UpdateUtf8cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
mosfet80 authored Jun 27, 2023
2 parents ce59d49 + d2411a7 commit 3da92e0
Show file tree
Hide file tree
Showing 16 changed files with 2,453 additions and 2,290 deletions.
5 changes: 5 additions & 0 deletions code/AssetLib/ASE/ASEParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,11 @@ void Parser::ParseLV1MaterialListBlock() {
if (TokenMatch(filePtr, "MATERIAL_COUNT", 14)) {
ParseLV4MeshLong(iMaterialCount);

if (UINT_MAX - iOldMaterialCount < iMaterialCount) {
LogWarning("Out of range: material index is too large");
return;
}

// now allocate enough storage to hold all materials
m_vMaterials.resize(iOldMaterialCount + iMaterialCount, Material("INVALID"));
continue;
Expand Down
19 changes: 9 additions & 10 deletions code/AssetLib/LWS/LWSLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,18 +632,17 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
nodes.push_back(d);
}
ASSIMP_LOG_ERROR("LWS: Unexpected keyword: \'Channel\'");
}

// important: index of channel
nodes.back().channels.emplace_back();
LWO::Envelope &env = nodes.back().channels.back();

env.index = strtoul10(c);
} else {
// important: index of channel
nodes.back().channels.emplace_back();
LWO::Envelope &env = nodes.back().channels.back();

// currently we can just interpret the standard channels 0...9
// (hack) assume that index-i yields the binary channel type from LWO
env.type = (LWO::EnvelopeType)(env.index + 1);
env.index = strtoul10(c);

// currently we can just interpret the standard channels 0...9
// (hack) assume that index-i yields the binary channel type from LWO
env.type = (LWO::EnvelopeType)(env.index + 1);
}
}
// 'Envelope': a single animation channel
else if ((*it).tokens[0] == "Envelope") {
Expand Down
39 changes: 33 additions & 6 deletions code/AssetLib/MD5/MD5Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,31 @@ bool MD5Parser::ParseSection(Section &out) {
char *sz = buffer;
while (!IsSpaceOrNewLine(*buffer)) {
++buffer;
if (buffer == bufferEnd)
return false;
}
out.mName = std::string(sz, (uintptr_t)(buffer - sz));
SkipSpaces();
while (IsSpace(*buffer)) {
++buffer;
if (buffer == bufferEnd)
return false;
}

bool running = true;
while (running) {
if ('{' == *buffer) {
// it is a normal section so read all lines
++buffer;
if (buffer == bufferEnd)
return false;
bool run = true;
while (run) {
if (!SkipSpacesAndLineEnd()) {
while (IsSpaceOrNewLine(*buffer)) {
++buffer;
if (buffer == bufferEnd)
return false;
}
if ('\0' == *buffer) {
return false; // seems this was the last section
}
if ('}' == *buffer) {
Expand All @@ -164,25 +177,39 @@ bool MD5Parser::ParseSection(Section &out) {
elem.szStart = buffer;

// terminate the line with zero
while (!IsLineEnd(*buffer))
while (!IsLineEnd(*buffer)) {
++buffer;
if (buffer == bufferEnd)
return false;
}
if (*buffer) {
++lineNumber;
*buffer++ = '\0';
if (buffer == bufferEnd)
return false;
}
}
break;
} else if (!IsSpaceOrNewLine(*buffer)) {
// it is an element at global scope. Parse its value and go on
sz = buffer;
while (!IsSpaceOrNewLine(*buffer++))
;
while (!IsSpaceOrNewLine(*buffer++)) {
if (buffer == bufferEnd)
return false;
}
out.mGlobalValue = std::string(sz, (uintptr_t)(buffer - sz));
continue;
}
break;
}
return SkipSpacesAndLineEnd();
if (buffer == bufferEnd)
return false;
while (IsSpaceOrNewLine(*buffer)) {
++buffer;
if (buffer == bufferEnd)
return false;
}
return '\0' != *buffer;
}

// ------------------------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions code/AssetLib/MDL/MDLMaterialLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,12 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(

aiString szFile;
const size_t iLen = strlen((const char *)szCurrent);
size_t iLen2 = iLen + 1;
iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
size_t iLen2 = iLen > (MAXLEN - 1) ? (MAXLEN - 1) : iLen;
memcpy(szFile.data, (const char *)szCurrent, iLen2);
szFile.data[iLen2] = '\0';
szFile.length = static_cast<ai_uint32>(iLen2);

szCurrent += iLen2;
szCurrent += iLen2 + 1;

// place this as diffuse texture
pcMatOut->AddProperty(&szFile, AI_MATKEY_TEXTURE_DIFFUSE(0));
Expand Down
5 changes: 3 additions & 2 deletions code/AssetLib/Obj/ObjFileMtlImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ void ObjFileMtlImporter::load() {
case 'a': // Anisotropy
{
++m_DataIt;
getFloatValue(m_pModel->mCurrentMaterial->anisotropy);
if (m_pModel->mCurrentMaterial != nullptr)
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
getFloatValue(m_pModel->mCurrentMaterial->anisotropy);
m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
} break;

default: {
Expand Down Expand Up @@ -371,6 +371,7 @@ void ObjFileMtlImporter::getTexture() {
if (m_pModel->mCurrentMaterial == nullptr) {
m_pModel->mCurrentMaterial = new ObjFile::Material();
m_pModel->mCurrentMaterial->MaterialName.Set("Empty_Material");
m_pModel->mMaterialMap["Empty_Material"] = m_pModel->mCurrentMaterial;
}

const char *pPtr(&(*m_DataIt));
Expand Down
15 changes: 13 additions & 2 deletions code/AssetLib/Obj/ObjFileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,19 @@ void ObjFileParser::getFace(aiPrimitiveType type) {
iPos = 0;
} else {
//OBJ USES 1 Base ARRAYS!!!!
const char *token = &(*m_DataIt);
const int iVal = ::atoi(token);
int iVal;
auto end = m_DataIt;
// find either the buffer end or the '\0'
while (end < m_DataItEnd && *end != '\0')
++end;
// avoid temporary string allocation if there is a zero
if (end != m_DataItEnd) {
iVal = ::atoi(&(*m_DataIt));
} else {
// otherwise make a zero terminated copy, which is safe to pass to atoi
std::string number(&(*m_DataIt), m_DataItEnd - m_DataIt);
iVal = ::atoi(number.c_str());
}

// increment iStep position based off of the sign and # of digits
int tmp = iVal;
Expand Down
1 change: 0 additions & 1 deletion code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,6 @@ IF(ASSIMP_HUNTER_ENABLED)
find_package(minizip CONFIG REQUIRED)
ELSE()
SET( unzip_SRCS
../contrib/unzip/crypt.c
../contrib/unzip/crypt.h
../contrib/unzip/ioapi.c
../contrib/unzip/ioapi.h
Expand Down
2 changes: 1 addition & 1 deletion code/Common/FileSystemFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class FileSystemFilter : public IOSystem
}

const char separator = getOsSeparator();
for (it = in.begin(); it != in.end(); ++it) {
for (it = in.begin(); it < in.end(); ++it) {
const size_t remaining = std::distance(in.end(), it);
// Exclude :// and \\, which remain untouched.
// https://sourceforge.net/tracker/?func=detail&aid=3031725&group_id=226462&atid=1067632
Expand Down
8 changes: 4 additions & 4 deletions code/Material/MaterialSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/material.h>
#include <assimp/types.h>
#include <assimp/DefaultLogger.hpp>
#include <memory>

using namespace Assimp;

Expand Down Expand Up @@ -473,7 +474,7 @@ aiReturn aiMaterial::AddBinaryProperty(const void *pInput,
}

// Allocate a new material property
aiMaterialProperty *pcNew = new aiMaterialProperty();
std::unique_ptr<aiMaterialProperty> pcNew(new aiMaterialProperty());

// .. and fill it
pcNew->mType = pType;
Expand All @@ -489,7 +490,7 @@ aiReturn aiMaterial::AddBinaryProperty(const void *pInput,
strcpy(pcNew->mKey.data, pKey);

if (UINT_MAX != iOutIndex) {
mProperties[iOutIndex] = pcNew;
mProperties[iOutIndex] = pcNew.release();
return AI_SUCCESS;
}

Expand All @@ -502,7 +503,6 @@ aiReturn aiMaterial::AddBinaryProperty(const void *pInput,
try {
ppTemp = new aiMaterialProperty *[mNumAllocated];
} catch (std::bad_alloc &) {
delete pcNew;
return AI_OUTOFMEMORY;
}

Expand All @@ -513,7 +513,7 @@ aiReturn aiMaterial::AddBinaryProperty(const void *pInput,
mProperties = ppTemp;
}
// push back ...
mProperties[mNumProperties++] = pcNew;
mProperties[mNumProperties++] = pcNew.release();

return AI_SUCCESS;
}
Expand Down
11 changes: 10 additions & 1 deletion code/PostProcessing/FindInvalidDataProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void UpdateMeshReferences(aiNode *node, const std::vector<unsigned int> &meshMap
for (unsigned int a = 0; a < node->mNumMeshes; ++a) {

unsigned int ref = node->mMeshes[a];
if (ref >= meshMapping.size())
throw DeadlyImportError("Invalid mesh ref");

if (UINT_MAX != (ref = meshMapping[ref])) {
node->mMeshes[out++] = ref;
}
Expand Down Expand Up @@ -143,7 +146,13 @@ void FindInvalidDataProcess::Execute(aiScene *pScene) {
// we need to remove some meshes.
// therefore we'll also need to remove all references
// to them from the scenegraph
UpdateMeshReferences(pScene->mRootNode, meshMapping);
try {
UpdateMeshReferences(pScene->mRootNode, meshMapping);
} catch (const std::exception&) {
// fix the real number of meshes otherwise we'll get double free in the scene destructor
pScene->mNumMeshes = real;
throw;
}
pScene->mNumMeshes = real;
}

Expand Down
Loading

0 comments on commit 3da92e0

Please sign in to comment.