Browse Source

Fix memory corruption in the aiGetExportFormatDescription() API. Clarify Exporter doc.

Alexander Gessler 11 years ago
parent
commit
be5fc42e16
3 changed files with 21 additions and 2 deletions
  1. 2 0
      code/AssimpCExport.cpp
  2. 5 0
      code/Exporter.cpp
  3. 14 2
      include/assimp/Exporter.hpp

+ 2 - 0
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);
 }
 

+ 5 - 0
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;
 }

+ 14 - 2
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