Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: 'assimp info' crashes with invalid files #4201

Open
4 tasks done
umlaeute opened this issue Nov 23, 2021 · 17 comments
Open
4 tasks done

Bug: 'assimp info' crashes with invalid files #4201

umlaeute opened this issue Nov 23, 2021 · 17 comments
Labels
Bug Global flag to mark a deviation from expected behaviour

Comments

@umlaeute
Copy link
Contributor

umlaeute commented Nov 23, 2021

short description

assimp info started to segfault when feeding it invalid files (like txt-files)

divide and conquer

triggering the problem

$ assimp version
------------------------------------------------------ 
Open Asset Import Library ("Assimp", https://github.com/assimp/assimp) 
 -- Commandline toolchain --
------------------------------------------------------ 

Version 5.1 -debug -shared -st (GIT commit 0)

$ assimp info test/models/WRL/credits.txt 
Launching asset import ...           OK
Validating postprocessing flags ...  OK
Segmentation fault
$ echo $?
139
$

expected behaviour

assimp should not crash but instead report an error, like it did with assimp-5.0.1

$ assimp version
------------------------------------------------------ 
Open Asset Import Library ("Assimp", https://github.com/assimp/assimp) 
 -- Commandline toolchain --
------------------------------------------------------ 

Version 5.0 -debug -shared -st (GIT commit 0)

$ assimp info test/models/WRL/credits.txt 
Launching asset import ...           OK
Validating postprocessing flags ...  OK
ERROR: Failed to load file: No suitable reader found for the file format of file "test/models/WRL/credits.txt".
assimp info: Unable to load input file test/models/WRL/credits.txt
$ echo $?
5
$

platform

  • Debian testing/sid
  • architecture: amd64
  • assimp-5.1.1
@umlaeute umlaeute added the Bug Global flag to mark a deviation from expected behaviour label Nov 23, 2021
@umlaeute
Copy link
Contributor Author

i haven't tested yet whether this is a problem with the assimp cmdline tool, or in the library.

@umlaeute
Copy link
Contributor Author

umlaeute commented Nov 23, 2021

i've checked with pyassimp, and there it fails gracefully.
so i guess the issue is really in the cmdline tool.

EDIT: scratch this. tests were running with assimp-5.0.1 (and i have unrelated problems with the pyassimp wrapper)

@pezcode
Copy link

pezcode commented Nov 24, 2021

Possibly related: #4177

@umlaeute
Copy link
Contributor Author

most probably you are right.
i did a backtrace last night and i seem to remember that it spit out X3D...

@kimkulling
Copy link
Member

This is a known issue with the detection routine of the X3D-Importer. There the CanRead-Method always returns true.

@kimkulling
Copy link
Member

Unfortunately, there is another issue.

@umlaeute
Copy link
Contributor Author

umlaeute commented Nov 25, 2021

ah because the argument to std::string::find_last_of is actually a set of characters rather than a string.
so it returns a result whenever any of ., x, 3 or d is found in the filename.

i guess the X3DImporter::CanRead should actually look like:

bool X3DImporter::CanRead(const std::string &pFile, IOSystem * /*pIOHandler*/, bool checkSig) const {
    if (checkSig) {
        std::string::size_type pos = pFile.rfind(".");
        if (pos != std::string::npos) {
            std::string ext=pFile.substr(pos+1);
            if ("x3d" == ext)
                return true;
        }
    }

    return false;
}

this fixes the crash for obvious non-X3D files.

however, the importer still crashes when trying to open a valid(?) X3D file:

$ build/bin/assimp info test/models/X3D/ComputerKeyboard.x3d 
Launching asset import ...           OK
Validating postprocessing flags ...  OK
here
Segmentation fault
$ echo $?
139

$ build/bin/assimp info test/models/OBJ/empty_mat.mtl 
Launching asset import ...           OK
Validating postprocessing flags ...  OK
ERROR: Failed to load file: BLEND: BLENDER magic bytes are missing, couldn't find GZIP header either
assimp info: Unable to load input file ../test/models/OBJ/empty_mat.mtl
$ echo $?
3

@umlaeute
Copy link
Contributor Author

umlaeute commented Nov 25, 2021

actually it only crashes on the ComputerKeyboard.x3d file.
HelloX3dTrademark.x3d can be read just fine.

$ gdb --args ./assimp info ../../test/models/X3D/ComputerKeyboard.x3d 
(gdb) run
Starting program: @PATH@/obj-x86_64-linux-gnu/bin/assimp info ../../test/models/X3D/ComputerKeyboard.x3d
Launching asset import ...           OK
Validating postprocessing flags ...  OK
here

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6de2a04 in std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*) () from /lib/x86_64-linux-gnu/libstdc++.so.6
(gdb) bt
#0  0x00007ffff6de2a04 in std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*) () from /lib/x86_64-linux-gnu/libstdc++.so.6
#1  0x00007ffff78bd9eb in void std::__cxx11::list<X3DNodeElementBase*, std::allocator<X3DNodeElementBase*> >::_M_insert<X3DNodeElementBase* const&>(std::_List_iterator<X3DNodeElementBase*>, X3DNodeElementBase* const&) ()
   from @PATH@/obj-x86_64-linux-gnu/bin/libassimp.so.5
#2  0x00007ffff78bd1aa in std::__cxx11::list<X3DNodeElementBase*, std::allocator<X3DNodeElementBase*> >::push_back(X3DNodeElementBase* const&) () from @PATH@/obj-x86_64-linux-gnu/bin/libassimp.so.5
#3  0x00007ffff78c2306 in Assimp::X3DImporter::MACRO_USE_CHECKANDAPPLY(pugi::xml_node&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, X3DElemType, X3DNodeElementBase*) () from @PATH@/obj-x86_64-linux-gnu/bin/libassimp.so.5
#4  0x00007ffff78cc041 in Assimp::X3DImporter::startReadTransform(pugi::xml_node&) () from @PATH@/obj-x86_64-linux-gnu/bin/libassimp.so.5
#5  0x00007ffff78bc403 in Assimp::X3DImporter::readChildNodes(pugi::xml_node&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
   from @PATH@/obj-x86_64-linux-gnu/bin/libassimp.so.5
#6  0x00007ffff78bc446 in Assimp::X3DImporter::readChildNodes(pugi::xml_node&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
   from @PATH@/obj-x86_64-linux-gnu/bin/libassimp.so.5
#7  0x00007ffff78bc7ab in Assimp::X3DImporter::readScene(pugi::xml_node&) () from @PATH@/obj-x86_64-linux-gnu/bin/libassimp.so.5
#8  0x00007ffff78bb40f in Assimp::X3DImporter::ParseFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Assimp::IOSystem*) ()
   from @PATH@/obj-x86_64-linux-gnu/bin/libassimp.so.5
#9  0x00007ffff78bb8e9 in Assimp::X3DImporter::InternReadFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, aiScene*, Assimp::IOSystem*) ()
   from @PATH@/obj-x86_64-linux-gnu/bin/libassimp.so.5
#10 0x00007ffff73207e0 in Assimp::BaseImporter::ReadFile(Assimp::Importer*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Assimp::IOSystem*) ()
   from @PATH@/obj-x86_64-linux-gnu/bin/libassimp.so.5
#11 0x00007ffff7336e8c in Assimp::Importer::ReadFile(char const*, unsigned int) () from @PATH@/obj-x86_64-linux-gnu/bin/libassimp.so.5
#12 0x0000555555574be6 in Assimp::Importer::ReadFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int) ()
#13 0x0000555555573656 in ImportModel(ImportData const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
#14 0x0000555555577f10 in Assimp_Info(char const* const*, unsigned int) ()
#15 0x00005555555733a1 in main ()
(gdb) 

umlaeute added a commit to umlaeute/assimp that referenced this issue Dec 1, 2021
Related: assimp#4201

while the crashes go away, i'm not sure whether this is the correct fix.
also, afaict the X3D importer produces wrong results anyhow
@Jenfong
Copy link

Jenfong commented Aug 24, 2023

cashed with fbx file.I'm not sure ,is the same root cause.
I build and install with assimp v5.0.1.tar.gz

[root@localhost soft]# gdb --args assimp info "Intergalactic_Spaceship.fbx"
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/local/bin/assimp...done.
(gdb) run
Starting program: /usr/local/bin/assimp info Intergalactic_Spaceship.fbx
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Launching asset import ...           OK
Validating postprocessing flags ...  OK
Importing file ...                   OK
   import took approx. 1.03646 seconds


Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6b12691 in Assimp::Importer::GetMemoryRequirements (this=0x7fffffffe2e0, in=...) at /home/soft/assimp/assimp-5.0.1/code/Common/Importer.cpp:1148
1148                in.animations += pc2->mNumPositionKeys * sizeof(aiVectorKey);
Missing separate debuginfos, use: debuginfo-install libgcc-4.8.5-44.el7.x86_64 zlib-1.2.7-21.el7_9.x86_64

(gdb) bt
#0  0x00007ffff6b12691 in Assimp::Importer::GetMemoryRequirements (this=0x7fffffffe2e0, in=...) at /home/soft/assimp/assimp-5.0.1/code/Common/Importer.cpp:1148
#1  0x0000000000428fce in Assimp_Info (params=0x7fffffffe458, num=1) at /home/soft/assimp/assimp-5.0.1/tools/assimp_cmd/Info.cpp:340
#2  0x0000000000420c7d in main (argc=3, argv=0x7fffffffe448) at /home/soft/assimp/assimp-5.0.1/tools/assimp_cmd/Main.cpp:207

fbx file info
[Intergalactic_Spaceship.fbx] https://sketchfab.com/3d-models/intergalactic-spaceship-241cc2f1487b44e8a1adf5abc8448746#download
system info

[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# lsb_release a
[root@localhost ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.9.2009 (Core)
Release:        7.9.2009
Codename:       Core

[root@localhost ~]# assimp version
------------------------------------------------------
Open Asset Import Library ("Assimp", https://github.com/assimp/assimp)
 -- Commandline toolchain --
------------------------------------------------------

Version 5.0 -debug -shared -st (GIT commit 0)
[root@localhost assimp]# ls
assimp-5.0.1  v5.0.1.tar.gz

@umlaeute
Copy link
Contributor Author

Thanks for the additional info. However, I think it would be more useful to try with a current release (5.0.1 was released 3.5 years ago. There have been a couple of other releases since then)

@Jenfong
Copy link

Jenfong commented Aug 25, 2023

Thanks for the additional info. However, I think it would be more useful to try with a current release (5.0.1 was released 3.5 years ago. There have been a couple of other releases since then)

howerver with assimp 5.10 ,some error blocked during compile the "test" folder:

@path/assimp/assimp - 5.1.0 / test/unit/utglTF2ImportExport CPP: In the member function 'virtual void utglTF2ImportExport_wrongTypes_Test::TestBody()' :

turn off warnnings and test , with config cmake .. -DASSIMP_WARNINGS_AS_ERRORS=OFF -DASSIMP_BUILD_TESTS=OFF ,it worked .

[root@localhost ~]# assimp version
------------------------------------------------------
Open Asset Import Library ("Assimp", https://github.com/assimp/assimp)
 -- Commandline toolchain --
------------------------------------------------------

Version 5.1 -debug -shared -st (GIT commit 0)

[root@localhost ~]# assimp info @path/Intergalactic_Spaceship.fbx
Launching asset import ...           OK
Validating postprocessing flags ...  OK
Importing file ...                   OK
   import took approx. 1.05299 seconds

Memory consumption: 3645875 B
Nodes:              2
Maximum depth       2
Meshes:             1
Animations:         14
Textures (embed.):  0
Materials:          1
Cameras:            0
Lights:             0
Vertices:           34186
Faces:              55120
Bones:              0
Animation Channels: 14
Primitive Types:    triangles
Average faces/mesh  55120
Average verts/mesh  34186
Minimum point      (-477.463257 -174.386124 -329.809937)
Maximum point      (477.432098 174.386032 247.822800)
Center point       (-0.015579 -0.000046 -40.993568)

Meshes:  (name) [vertices / bones / faces | primitive_types]
    0 (RetopoGroup2): [34186 / 0 / 55120 | triangle]

Named Materials:
    'Material'

Texture Refs:
    '..\textures\Intergalactic Spaceship_color_4.jpg'
    '..\textures\Intergalactic Spaceship_rough.jpg'
    '..\textures\Intergalactic Spaceship_nmap_2_Tris.jpg'

Named Animations:
     'Intergalactic Spaceship|CircleAction.004'
     'Intergalactic Spaceship|CircleAction.005'
     'Intergalactic Spaceship|RetopoGroup2Action.002'
     'Intergalactic Spaceship|SphereAction'
     'Intergalactic Spaceship|SphereAction.002'
     'Intergalactic Spaceship|Torus.004Action.013'
     'Intergalactic Spaceship|Torus.004Action.014'
     'Intergalactic Spaceship|Torus.004Action.015'
     'Intergalactic Spaceship|Torus.004Action.016'
     'Intergalactic Spaceship|Torus.004Action.017'
     'Intergalactic Spaceship|Torus.004Action.018'
     'Intergalactic Spaceship|Torus.004Action.019'
     'Intergalactic Spaceship|Torus.004Action.020'

Node hierarchy:
RootNode
└╴Intergalactic Spaceship (mesh 0)

@umlaeute
Copy link
Contributor Author

5.1.0 was released almost 2 years ago, the have been a dozen of feature&bugfix releases in the meantime.

So: Could you please try with current assimp?
At the time of writing this is v5.2.5.

If that still has problems, would it be possible to try with current master?

@Jenfong
Copy link

Jenfong commented Aug 25, 2023

5.1.0 was released almost 2 years ago, the have been a dozen of feature&bugfix releases in the meantime.

So: Could you please try with current assimp? At the time of writing this is v5.2.5.

If that still has problems, would it be possible to try with current master?

cmake failed

[root@localhost build]# pwd
/home/soft/assimp/assimp-5.2.5/build
[root@localhost build]# cmake ..
-- Shared libraries enabled
-- Looking for ZLIB...
-- Checking for module 'zzip-zlib-config'
--   No package 'zzip-zlib-config' found
-- Found ZLIB: optimized;/usr/lib64/libz.so;debug;/usr/lib64/libz.so
-- Enabled importer formats: AMF 3DS AC ASE ASSBIN B3D BVH COLLADA DXF CSM HMP IRRMESH IQM IRR LWO LWS M3D MD2 MD3 MD5 MDC MDL NFF NDO OFF OBJ OGRE OPENGEX PLY MS3D COB BLEND IFC XGL FBX Q3D Q3BSP RAW SIB SMD STL TERRAGEN 3D X X3D GLTF 3MF MMD
-- Disabled importer formats:
-- Enabled exporter formats: OBJ OPENGEX PLY 3DS ASSBIN ASSXML M3D COLLADA FBX STL X X3D GLTF 3MF PBRT ASSJSON STEP
-- Disabled exporter formats:
-- Configuring done
CMake Error in code/CMakeLists.txt:
  Target "assimp" requires the language dialect "CXX17" (with compiler
  extensions), but CMake does not know the compile flags to use to enable it.


-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

cmake and gcc version
cmake --version
cmake version 3.19.5
gcc -v
gcc version11.2.0 (GCC)

@umlaeute
Copy link
Contributor Author

i don't see any failure in the snippet you provided.

@Jenfong
Copy link

Jenfong commented Sep 1, 2023

i don't see any failure in the snippet you provided.

sorry,updated #4201 (comment) the comment.
build with error:
CMake Error in code/CMakeLists.txt: Target "assimp" requires the language dialect "CXX17" (with compiler extensions), but CMake does not know the compile flags to use to enable it.

@umlaeute
Copy link
Contributor Author

umlaeute commented Sep 1, 2023

a quick google search gives me https://stackoverflow.com/questions/47238577/ which indicates that you should upgrade your CMake installation to CMake>=3.8 (CMake-3.8 was released in 2017), and make sure that you are using a compiler that can handle C++17 (e.g. gcc>=5.1.0).

why it doesn't work with your cmake-3.19 and gcc-11.2 is a mystery to me.

@umlaeute
Copy link
Contributor Author

umlaeute commented Sep 1, 2023

also, your cmake-log seems to be incomplete.

e.g. when i run cmake, the entire output that is produced is:

$ cmake ..
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Shared libraries enabled
-- Looking for ZLIB...
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1") 
-- Checking for module 'zzip-zlib-config'
--   Package 'zzip-zlib-config', required by 'virtual:world', not found
-- Found ZLIB: optimized;/usr/lib/x86_64-linux-gnu/libz.so;debug;/usr/lib/x86_64-linux-gnu/libz.so
-- Checking for module 'minizip'
--   Found minizip, version 1.2.13
-- Enabled importer formats: AMF 3DS AC ASE ASSBIN B3D BVH COLLADA DXF CSM HMP IRRMESH IQM IRR LWO LWS M3D MD2 MD3 MD5 MDC MDL NFF NDO OFF OBJ OGRE OPENGEX PLY MS3D COB BLEND IFC XGL FBX Q3D Q3BSP RAW SIB SMD STL TERRAGEN 3D X X3D GLTF 3MF MMD
-- Disabled importer formats:
-- Enabled exporter formats: OBJ OPENGEX PLY 3DS ASSBIN ASSXML M3D COLLADA FBX STL X X3D GLTF 3MF PBRT ASSJSON STEP
-- Disabled exporter formats:
-- Treating all warnings as errors (for assimp library only)
-- Configuring done (0.5s)
-- Generating done (0.0s)
-- Build files have been written to: <<srcdir>>/assimp/build

and for the sake of completeness:

$ cmake --version
cmake version 3.27.4

CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ g++ --version
g++ (Debian 13.2.0-2) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Global flag to mark a deviation from expected behaviour
Projects
Status: No status
Development

No branches or pull requests

4 participants