You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
C interface for Exporter cannot get format descriptions #693
The C interface for Exporter has a bug. The function aiGetExportFormatDescription( index ) performs Exporter().GetExportFormatDescription( index ). However, this returns temporary memory. Attempting to access the returned aiExportFormatDesc results in a segfault. The solution is either to return a pointer to the global array of aiExportFormatDesc or to return a copy of the aiExportFormatDesc struct with a corresponding free function.
The following fails:
// brew install assimp
// cc cexport_bug.c -o cexport_bug -I/usr/local/include -L/usr/local/lib -lassimp
#include <stdio.h>
#include <assimp/cexport.h>
int main( int argc, char* argv[] ) {
// Get the count
const size_t count = aiGetExportFormatCount();
for( size_t i = 0; i < count; ++i )
{
// Get the description.
const struct aiExportFormatDesc* desc = aiGetExportFormatDescription( i );
// desc points to free'd memory. The following crashes or prints garbage.
printf( "%s: %s (id: %s)\n", desc->fileExtension, desc->description, desc->id );
}
return 0;
}
The following works:
// brew install assimp
// c++ cexport_works.c -o cexport_works -I/usr/local/include -L/usr/local/lib -lassimp
#include <stdio.h>
#include <assimp/Exporter.hpp>
int main( int argc, char* argv[] ) {
// Allocate an Exporter.
Assimp::Exporter exporter;
// Get the count
const size_t count = exporter.GetExportFormatCount();
for( size_t i = 0; i < count; ++i )
{
// Get the description.
const aiExportFormatDesc* desc = exporter.GetExportFormatDescription( i );
// desc does not point to free'd memory. The following works.
printf( "%s: %s (id: %s)\n", desc->fileExtension, desc->description, desc->id );
}
return 0;
}
Activity
kimkulling commentedon Nov 23, 2015
Now the description will be copied.
kimkulling commentedon Nov 23, 2015
Thanks for reporting this issue!
yig commentedon Nov 24, 2015
I looked at the fix, but it seems to have the same problem: https://github.com/assimp/assimp/blob/master/code/AssimpCExport.cpp#L66
The line
is still storing a pointer to an already free'd object.
The correct solution is to create an
Exporterat the beginning of the function and use it. I will create a pull request.Update CMakeLists.txt
Update CMakeLists.txt (#5379)
Update CMakeLists.txt (#5379)