Merge branch 'master' into fix-fbx-utils-buffer-overflow

pull/5322/head
Kim Kulling 2023-11-29 10:55:47 +01:00 committed by GitHub
commit 216bff27ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 92 additions and 111 deletions

View File

@ -43,6 +43,7 @@ cd assimp
cmake CMakeLists.txt cmake CMakeLists.txt
cmake --build . cmake --build .
``` ```
Note that by default this builds a shared library into the `bin` directory. If you want to build it as a static library see the build options at the bottom of this file.
### Build instructions for Windows with Visual-Studio ### Build instructions for Windows with Visual-Studio

View File

@ -35,7 +35,7 @@ And we also have a Gitter-channel:Gitter [![Join the chat at https://gitter.im/a
You can find the complete list of supported file-formats [here](https://github.com/assimp/assimp/blob/master/doc/Fileformats.md) You can find the complete list of supported file-formats [here](https://github.com/assimp/assimp/blob/master/doc/Fileformats.md)
### Building ### ### Building ###
Take a look into the https://github.com/assimp/assimp/blob/master/Build.md file. We are available in vcpkg, and our build system is CMake; if you used CMake before there is a good chance you know what to do. Take a look [here](https://github.com/assimp/assimp/blob/master/Build.md) to get started. We are available in vcpkg, and our build system is CMake; if you used CMake before there is a good chance you know what to do.
### Ports ### ### Ports ###
* [Android](port/AndroidJNI/README.md) * [Android](port/AndroidJNI/README.md)
@ -52,7 +52,7 @@ Take a look into the https://github.com/assimp/assimp/blob/master/Build.md file.
### Other tools ### ### Other tools ###
[open3mod](https://github.com/acgessler/open3mod) is a powerful 3D model viewer based on Assimp's import and export abilities. [open3mod](https://github.com/acgessler/open3mod) is a powerful 3D model viewer based on Assimp's import and export abilities.
[Assimp-Viewer(]https://github.com/assimp/assimp_view) is an experimental implementation for an Asset-Viewer based on ImGUI and Assimp (experimental). [Assimp-Viewer](https://github.com/assimp/assimp_view) is an experimental implementation for an Asset-Viewer based on ImGUI and Assimp (experimental).
#### Repository structure #### #### Repository structure ####
Open Asset Import Library is implemented in C++. The directory structure looks like this: Open Asset Import Library is implemented in C++. The directory structure looks like this:

View File

@ -186,9 +186,6 @@ D3MFOpcPackage::D3MFOpcPackage(IOSystem *pIOHandler, const std::string &rFile) :
D3MFOpcPackage::~D3MFOpcPackage() { D3MFOpcPackage::~D3MFOpcPackage() {
mZipArchive->Close(mRootStream); mZipArchive->Close(mRootStream);
delete mZipArchive; delete mZipArchive;
for (auto tex : mEmbeddedTextures) {
delete tex;
}
} }
IOStream *D3MFOpcPackage::RootStream() const { IOStream *D3MFOpcPackage::RootStream() const {

View File

@ -50,11 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/version.h> #include <assimp/version.h>
#include <assimp/IOStream.hpp> #include <assimp/IOStream.hpp>
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB #include "zlib.h"
#include <zlib.h>
#else
#include "../contrib/zlib/zlib.h"
#endif
#include <ctime> #include <ctime>

View File

@ -283,6 +283,11 @@ void BlenderModifier_Subdivision ::DoIt(aiNode &out, ConversionData &conv_data,
if (conv_data.meshes->empty()) { if (conv_data.meshes->empty()) {
return; return;
} }
const size_t meshIndex = conv_data.meshes->size() - out.mNumMeshes;
if (meshIndex >= conv_data.meshes->size()) {
ASSIMP_LOG_ERROR("Invalid index detected.");
return;
}
aiMesh **const meshes = &conv_data.meshes[conv_data.meshes->size() - out.mNumMeshes]; aiMesh **const meshes = &conv_data.meshes[conv_data.meshes->size() - out.mNumMeshes];
std::unique_ptr<aiMesh *[]> tempmeshes(new aiMesh *[out.mNumMeshes]()); std::unique_ptr<aiMesh *[]> tempmeshes(new aiMesh *[out.mNumMeshes]());

View File

@ -814,38 +814,38 @@ void ColladaParser::ReadImage(XmlNode &node, Collada::Image &pImage) {
if (!pImage.mFileName.length()) { if (!pImage.mFileName.length()) {
pImage.mFileName = "unknown_texture"; pImage.mFileName = "unknown_texture";
} }
} } else if (mFormat == FV_1_5_n) {
} else if (mFormat == FV_1_5_n) { std::string value;
std::string value; XmlNode refChild = currentNode.child("ref");
XmlNode refChild = currentNode.child("ref"); XmlNode hexChild = currentNode.child("hex");
XmlNode hexChild = currentNode.child("hex"); if (refChild) {
if (refChild) { // element content is filename - hopefully
// element content is filename - hopefully if (XmlParser::getValueAsString(refChild, value)) {
if (XmlParser::getValueAsString(refChild, value)) { aiString filepath(value);
aiString filepath(value); UriDecodePath(filepath);
UriDecodePath(filepath); pImage.mFileName = filepath.C_Str();
pImage.mFileName = filepath.C_Str(); }
} } else if (hexChild && !pImage.mFileName.length()) {
} else if (hexChild && !pImage.mFileName.length()) { // embedded image. get format
// embedded image. get format pImage.mEmbeddedFormat = hexChild.attribute("format").as_string();
pImage.mEmbeddedFormat = hexChild.attribute("format").as_string(); if (pImage.mEmbeddedFormat.empty()) {
if (pImage.mEmbeddedFormat.empty()) { ASSIMP_LOG_WARN("Collada: Unknown image file format");
ASSIMP_LOG_WARN("Collada: Unknown image file format"); }
}
XmlParser::getValueAsString(hexChild, value); XmlParser::getValueAsString(hexChild, value);
const char *data = value.c_str(); const char *data = value.c_str();
// hexadecimal-encoded binary octets. First of all, find the // hexadecimal-encoded binary octets. First of all, find the
// required buffer size to reserve enough storage. // required buffer size to reserve enough storage.
const char *cur = data; const char *cur = data;
while (!IsSpaceOrNewLine(*cur)) { while (!IsSpaceOrNewLine(*cur)) {
++cur; ++cur;
} }
const unsigned int size = (unsigned int)(cur - data) * 2; const unsigned int size = (unsigned int)(cur - data) * 2;
pImage.mImageData.resize(size); pImage.mImageData.resize(size);
for (unsigned int i = 0; i < size; ++i) { for (unsigned int i = 0; i < size; ++i) {
pImage.mImageData[i] = HexOctetToDecimal(data + (i << 1)); pImage.mImageData[i] = HexOctetToDecimal(data + (i << 1));
}
} }
} }
} }
@ -1274,9 +1274,7 @@ void ColladaParser::ReadEffectParam(XmlNode &node, Collada::EffectParam &pParam)
return; return;
} }
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode); for (XmlNode &currentNode : node.children()) {
XmlNode currentNode;
while (xmlIt.getNext(currentNode)) {
const std::string &currentName = currentNode.name(); const std::string &currentName = currentNode.name();
if (currentName == "surface") { if (currentName == "surface") {
// image ID given inside <init_from> tags // image ID given inside <init_from> tags
@ -1289,22 +1287,24 @@ void ColladaParser::ReadEffectParam(XmlNode &node, Collada::EffectParam &pParam)
} }
} else if (currentName == "sampler2D" && (FV_1_4_n == mFormat || FV_1_3_n == mFormat)) { } else if (currentName == "sampler2D" && (FV_1_4_n == mFormat || FV_1_3_n == mFormat)) {
// surface ID is given inside <source> tags // surface ID is given inside <source> tags
const char *content = currentNode.value(); XmlNode source = currentNode.child("source");
pParam.mType = Param_Sampler; if (source) {
pParam.mReference = content; std::string v;
XmlParser::getValueAsString(source, v);
pParam.mType = Param_Sampler;
pParam.mReference = v.c_str();
}
} else if (currentName == "sampler2D") { } else if (currentName == "sampler2D") {
// surface ID is given inside <instance_image> tags // surface ID is given inside <instance_image> tags
std::string url; XmlNode instance_image = currentNode.child("instance_image");
XmlParser::getStdStrAttribute(currentNode, "url", url); if (instance_image) {
if (url[0] != '#') { std::string url;
throw DeadlyImportError("Unsupported URL format in instance_image"); XmlParser::getStdStrAttribute(instance_image, "url", url);
} if (url[0] != '#') {
pParam.mType = Param_Sampler; throw DeadlyImportError("Unsupported URL format in instance_image");
pParam.mReference = url.c_str() + 1; }
} else if (currentName == "source") { pParam.mType = Param_Sampler;
const char *source = currentNode.child_value(); pParam.mReference = url.c_str() + 1;
if (nullptr != source) {
pParam.mReference = source;
} }
} }
} }

View File

@ -55,9 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/MathFunctions.h> #include <assimp/MathFunctions.h>
#include <assimp/StringComparison.h> #include <assimp/StringComparison.h>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/CreateAnimMesh.h> #include <assimp/CreateAnimMesh.h>
#include <assimp/StringUtils.h> #include <assimp/StringUtils.h>
#include <assimp/commonMetaData.h> #include <assimp/commonMetaData.h>
@ -1604,7 +1602,7 @@ void FBXConverter::ConvertWeights(aiMesh *out, const MeshGeometry &geo, const ai
void FBXConverter::ConvertCluster(std::vector<aiBone*> &local_mesh_bones, const Cluster *cluster, void FBXConverter::ConvertCluster(std::vector<aiBone*> &local_mesh_bones, const Cluster *cluster,
std::vector<size_t> &out_indices, std::vector<size_t> &index_out_indices, std::vector<size_t> &out_indices, std::vector<size_t> &index_out_indices,
std::vector<size_t> &count_out_indices, const aiMatrix4x4 & /* absolute_transform*/, std::vector<size_t> &count_out_indices, const aiMatrix4x4 &absolute_transform,
aiNode *) { aiNode *) {
ai_assert(cluster != nullptr); // make sure cluster valid ai_assert(cluster != nullptr); // make sure cluster valid
@ -1621,16 +1619,16 @@ void FBXConverter::ConvertCluster(std::vector<aiBone*> &local_mesh_bones, const
bone = new aiBone(); bone = new aiBone();
bone->mName = bone_name; bone->mName = bone_name;
bone->mOffsetMatrix = cluster->Transform(); //bone->mOffsetMatrix = cluster->Transform();
// store local transform link for post processing // store local transform link for post processing
/*
bone->mOffsetMatrix = cluster->TransformLink(); bone->mOffsetMatrix = cluster->TransformLink();
bone->mOffsetMatrix.Inverse(); bone->mOffsetMatrix.Inverse();
aiMatrix4x4 matrix = (aiMatrix4x4)absolute_transform; const aiMatrix4x4 matrix = (aiMatrix4x4)absolute_transform;
bone->mOffsetMatrix = bone->mOffsetMatrix * matrix; // * mesh_offset bone->mOffsetMatrix = bone->mOffsetMatrix * matrix; // * mesh_offset
*/
// //
// Now calculate the aiVertexWeights // Now calculate the aiVertexWeights
// //

View File

@ -390,7 +390,7 @@ void Document::ReadObjects() {
const auto foundObject = objects.find(id); const auto foundObject = objects.find(id);
if(foundObject != objects.end()) { if(foundObject != objects.end()) {
DOMWarning("encountered duplicate object id, ignoring first occurrence",el.second); DOMWarning("encountered duplicate object id, ignoring first occurrence",el.second);
delete foundObject->second; delete_LazyObject(foundObject->second);
} }
objects[id] = new_LazyObject(id, *el.second, *this); objects[id] = new_LazyObject(id, *el.second, *this);

View File

@ -1061,14 +1061,14 @@ aiMatrix4x4 get_world_transform(const aiNode* node, const aiScene* scene)
return transform; return transform;
} }
int64_t to_ktime(double ticks, const aiAnimation* anim) { inline int64_t to_ktime(double ticks, const aiAnimation* anim) {
if (anim->mTicksPerSecond <= 0) { if (anim->mTicksPerSecond <= 0) {
return static_cast<int64_t>(ticks) * FBX::SECOND; return static_cast<int64_t>(ticks) * FBX::SECOND;
} }
return (static_cast<int64_t>(ticks) / static_cast<int64_t>(anim->mTicksPerSecond)) * FBX::SECOND; return (static_cast<int64_t>(ticks / anim->mTicksPerSecond)) * FBX::SECOND;
} }
int64_t to_ktime(double time) { inline int64_t to_ktime(double time) {
return (static_cast<int64_t>(time * FBX::SECOND)); return (static_cast<int64_t>(time * FBX::SECOND));
} }
@ -2413,7 +2413,7 @@ void FBXExporter::WriteObjects ()
// position/translation // position/translation
for (size_t ki = 0; ki < na->mNumPositionKeys; ++ki) { for (size_t ki = 0; ki < na->mNumPositionKeys; ++ki) {
const aiVectorKey& k = na->mPositionKeys[ki]; const aiVectorKey& k = na->mPositionKeys[ki];
times.push_back(to_ktime(k.mTime)); times.push_back(to_ktime(k.mTime, anim));
xval.push_back(k.mValue.x); xval.push_back(k.mValue.x);
yval.push_back(k.mValue.y); yval.push_back(k.mValue.y);
zval.push_back(k.mValue.z); zval.push_back(k.mValue.z);
@ -2427,7 +2427,7 @@ void FBXExporter::WriteObjects ()
times.clear(); xval.clear(); yval.clear(); zval.clear(); times.clear(); xval.clear(); yval.clear(); zval.clear();
for (size_t ki = 0; ki < na->mNumRotationKeys; ++ki) { for (size_t ki = 0; ki < na->mNumRotationKeys; ++ki) {
const aiQuatKey& k = na->mRotationKeys[ki]; const aiQuatKey& k = na->mRotationKeys[ki];
times.push_back(to_ktime(k.mTime)); times.push_back(to_ktime(k.mTime, anim));
// TODO: aiQuaternion method to convert to Euler... // TODO: aiQuaternion method to convert to Euler...
aiMatrix4x4 m(k.mValue.GetMatrix()); aiMatrix4x4 m(k.mValue.GetMatrix());
aiVector3D qs, qr, qt; aiVector3D qs, qr, qt;
@ -2445,7 +2445,7 @@ void FBXExporter::WriteObjects ()
times.clear(); xval.clear(); yval.clear(); zval.clear(); times.clear(); xval.clear(); yval.clear(); zval.clear();
for (size_t ki = 0; ki < na->mNumScalingKeys; ++ki) { for (size_t ki = 0; ki < na->mNumScalingKeys; ++ki) {
const aiVectorKey& k = na->mScalingKeys[ki]; const aiVectorKey& k = na->mScalingKeys[ki];
times.push_back(to_ktime(k.mTime)); times.push_back(to_ktime(k.mTime, anim));
xval.push_back(k.mValue.x); xval.push_back(k.mValue.x);
yval.push_back(k.mValue.y); yval.push_back(k.mValue.y);
zval.push_back(k.mValue.z); zval.push_back(k.mValue.z);

View File

@ -45,12 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
//#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
#include "Common/Compression.h" #include "Common/Compression.h"
//# include <zlib.h>
//#else
//# include "../contrib/zlib/zlib.h"
//#endif
#include "FBXTokenizer.h" #include "FBXTokenizer.h"
#include "FBXParser.h" #include "FBXParser.h"

View File

@ -42,11 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <utility> #include <utility>
#include "MMDPmxParser.h" #include "MMDPmxParser.h"
#include <assimp/StringUtils.h> #include <assimp/StringUtils.h>
#ifdef ASSIMP_USE_HUNTER #include "utf8.h"
# include <utf8.h>
#else
# include "../contrib/utf8cpp/source/utf8.h"
#endif
#include <assimp/Exceptional.h> #include <assimp/Exceptional.h>
namespace pmx namespace pmx
@ -93,7 +89,7 @@ namespace pmx
{ {
return std::string(); return std::string();
} }
buffer.reserve(size); buffer.resize(size);
stream->read((char*) buffer.data(), size); stream->read((char*) buffer.data(), size);
if (encoding == 0) if (encoding == 0)
{ {

View File

@ -605,7 +605,8 @@ void ObjFileParser::getMaterialDesc() {
} }
if (needsNewMesh(strName)) { if (needsNewMesh(strName)) {
createMesh(strName); auto newMeshName = m_pModel->mActiveGroup.empty() ? strName : m_pModel->mActiveGroup;
createMesh(newMeshName);
} }
m_pModel->mCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strName); m_pModel->mCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strName);

View File

@ -425,7 +425,8 @@ bool PLY::DOM::ParseHeader(IOStreamBuffer<char> &streamBuffer, std::vector<char>
break; break;
} else { } else {
// ignore unknown header elements // ignore unknown header elements
streamBuffer.getNextLine(buffer); if (!streamBuffer.getNextLine(buffer))
return false;
} }
} }

View File

@ -48,11 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/DefaultLogger.hpp> #include <assimp/DefaultLogger.hpp>
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB #include "zlib.h"
#include <zlib.h>
#else
#include "../contrib/zlib/zlib.h"
#endif
#include <assimp/DefaultIOSystem.h> #include <assimp/DefaultIOSystem.h>
#include <assimp/StringComparison.h> #include <assimp/StringComparison.h>

View File

@ -56,11 +56,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/ByteSwapper.h> #include <assimp/ByteSwapper.h>
#include <assimp/StreamReader.h> #include <assimp/StreamReader.h>
#include <assimp/TinyFormatter.h> #include <assimp/TinyFormatter.h>
#ifdef ASSIMP_USE_HUNTER #include "utf8.h"
#include <utf8.h>
#else
#include "../contrib/utf8cpp/source/utf8.h"
#endif
#include <assimp/importerdesc.h> #include <assimp/importerdesc.h>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/DefaultLogger.hpp> #include <assimp/DefaultLogger.hpp>

View File

@ -45,11 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "STEPFileEncoding.h" #include "STEPFileEncoding.h"
#include <assimp/fast_atof.h> #include <assimp/fast_atof.h>
#ifdef ASSIMP_USE_HUNTER #include "utf8.h"
# include <utf8.h>
#else
# include <contrib/utf8cpp/source/utf8.h>
#endif
#include <memory> #include <memory>

View File

@ -559,7 +559,11 @@ void glTF2Exporter::GetMatTex(const aiMaterial &mat, Ref<Texture> &texture, unsi
aiString tex; aiString tex;
// Read texcoord (UV map index) // Read texcoord (UV map index)
mat.Get(AI_MATKEY_UVWSRC(tt, slot), texCoord); // Note: must be an int to be successful.
int tmp = 0;
const auto ok = mat.Get(AI_MATKEY_UVWSRC(tt, slot), tmp);
if (ok == aiReturn_SUCCESS) texCoord = tmp;
if (mat.Get(AI_MATKEY_TEXTURE(tt, slot), tex) == AI_SUCCESS) { if (mat.Get(AI_MATKEY_TEXTURE(tt, slot), tex) == AI_SUCCESS) {
std::string path = tex.C_Str(); std::string path = tex.C_Str();

View File

@ -357,11 +357,7 @@ std::string BaseImporter::GetExtension(const std::string &pFile) {
return false; return false;
} }
#ifdef ASSIMP_USE_HUNTER #include "utf8.h"
#include <utf8.h>
#else
#include "../contrib/utf8cpp/source/utf8.h"
#endif
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Convert to UTF8 data // Convert to UTF8 data

View File

@ -41,11 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once #pragma once
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB #include "zlib.h"
# include <zlib.h>
#else
# include "../contrib/zlib/zlib.h"
#endif
#include <vector> #include <vector>
#include <cstddef> // size_t #include <cstddef> // size_t

View File

@ -287,7 +287,7 @@ static AI_FORCE_INLINE bool isEndOfCache(size_t pos, size_t cacheSize) {
template <class T> template <class T>
AI_FORCE_INLINE bool IOStreamBuffer<T>::getNextLine(std::vector<T> &buffer) { AI_FORCE_INLINE bool IOStreamBuffer<T>::getNextLine(std::vector<T> &buffer) {
buffer.resize(m_cacheSize); buffer.resize(m_cacheSize);
if (isEndOfCache(m_cachePos, m_cacheSize) || 0 == m_filePos) { if (m_cachePos >= m_cacheSize || 0 == m_filePos) {
if (!readNextBlock()) { if (!readNextBlock()) {
return false; return false;
} }

View File

@ -196,3 +196,10 @@ TEST_F(utPLYImportExport, parseErrorTest) {
const aiScene *scene = importer.ReadFileFromMemory(test_file, strlen(test_file), 0); const aiScene *scene = importer.ReadFileFromMemory(test_file, strlen(test_file), 0);
EXPECT_NE(nullptr, scene); EXPECT_NE(nullptr, scene);
} }
// This file is invalid, we just want to ensure that the importer is not crashing
TEST_F(utPLYImportExport, parseInvalid) {
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/invalid/crash-30d6d0f7c529b3b66b4131700b7a4580cd7082df.ply", 0);
EXPECT_EQ(nullptr, scene);
}