From be5fc42e161300c0691df0ad1630961ee0da77bc Mon Sep 17 00:00:00 2001 From: Alexander Gessler Date: Tue, 17 Jun 2014 16:10:55 +0200 Subject: [PATCH] Fix memory corruption in the aiGetExportFormatDescription() API. Clarify Exporter doc. --- code/AssimpCExport.cpp | 2 ++ code/Exporter.cpp | 5 +++++ include/assimp/Exporter.hpp | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/code/AssimpCExport.cpp b/code/AssimpCExport.cpp index 053e1b9f4..70a5177da 100644 --- a/code/AssimpCExport.cpp +++ b/code/AssimpCExport.cpp @@ -61,6 +61,8 @@ ASSIMP_API size_t aiGetExportFormatCount(void) // ------------------------------------------------------------------------------------------------ ASSIMP_API const aiExportFormatDesc* aiGetExportFormatDescription( size_t pIndex) { + // Note: this is valid as the index always pertains to a builtin exporter, + // for which the returned structure is guaranteed to be of static storage duration. return Exporter().GetExportFormatDescription(pIndex); } diff --git a/code/Exporter.cpp b/code/Exporter.cpp index a693f75e2..6b2bfa173 100644 --- a/code/Exporter.cpp +++ b/code/Exporter.cpp @@ -436,6 +436,11 @@ const aiExportFormatDesc* Exporter :: GetExportFormatDescription( size_t pIndex if (pIndex >= GetExportFormatCount()) { return NULL; } + + // Return from static storage if the requested index is built-in. + if (pIndex < sizeof(gExporters) / sizeof(gExporters[0])) { + return &gExporters[pIndex].mDescription; + } return &pimpl->mExporters[pIndex].mDescription; } diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index b9318ae29..d8ce6fa72 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -251,7 +251,11 @@ public: // ------------------------------------------------------------------- /** Returns the number of export file formats available in the current * Assimp build. Use #Exporter::GetExportFormatDescription to - * retrieve infos of a specific export format */ + * retrieve infos of a specific export format. + * + * This includes built-in exporters as well as exporters registered + * using #RegisterExporter. + **/ size_t GetExportFormatCount() const; @@ -259,6 +263,12 @@ public: /** Returns a description of the nth export file format. Use # * #Exporter::GetExportFormatCount to learn how many export * formats are supported. + * + * The returned pointer is of static storage duration iff the + * pIndex pertains to a built-in exporter (i.e. one not registered + * via #RegistrerExporter). It is restricted to the life-time of the + * #Exporter instance otherwise. + * * @param pIndex Index of the export format to retrieve information * for. Valid range is 0 to #Exporter::GetExportFormatCount * @return A description of that specific export format. @@ -269,7 +279,9 @@ public: // ------------------------------------------------------------------- /** Register a custom exporter. Custom export formats are limited to * to the current #Exporter instance and do not affect the - * library globally. + * library globally. The indexes under which the format's + * export format description can be queried are assigned + * monotonously. * @param desc Exporter description. * @return aiReturn_SUCCESS if the export format was successfully * registered. A common cause that would prevent an exporter