Skip to content

Bug: .3mf files fail to load #5328

Open
Open

Description

@tellypresence

.3mf files in these archives:

hang on load. No apparent errors, load never completes.

Activity

  1. added
    Bug
    on Nov 17, 2023
  2. stephengold commented on Nov 18, 2023

    @stephengold
    Contributor

    I tried importing both files using assimp info (built at Git hash 6004290) and there was no hang.

    @tellypresence What tool are you using to load these files?

  3. added
    3MF
    on Nov 23, 2023
  4. stephengold commented on Nov 23, 2023

    @stephengold
    Contributor

    When I use LWJGL 3.3.4 snapshot build 2 (built at Assimp git hash 56e0ba5) my application crashes while importing truck.3mf. The exact behavior varies from run to run, which might be a symptom of uninitialized data.

    Here is the output of my application with verbose logging enabled:

    Info,  T0: Load truck.3mf
    Debug, T0: Assimp 5.3.0 amd64 gcc shared singlethreadedsingle : 
    Info,  T0: Found a matching importer for this file format: 3mf Importer.
    Info,  T0: Import root directory is './'
    Warn,  T0: Ignored file of unknown type: 3D/3dmodel.model
    Warn,  T0: Ignored file of unknown type: 3D/Texture/CMC_LOGO_COLOR.png
    Warn,  T0: Ignored file of unknown type: 3D/_rels/3dmodel.model.rels
    Warn,  T0: Ignored file of unsupported type CONTENT_TYPES_ARCHIVES[Content_Types].xml
    Debug, T0: 3D/3dmodel.model
    Debug, T0: UpdateImporterScale scale set: 1
    Debug, T0: ValidateDataStructureProcess begin
    Error, T0: Validation failed: aiTexture::achFormatHint contains non-lowercase letters
    free(): invalid pointer

    Here is another run with the same inputs:

    Info,  T0: Load truck.3mf
    Debug, T0: Assimp 5.3.0 amd64 gcc shared singlethreadedsingle : 
    Info,  T0: Found a matching importer for this file format: 3mf Importer.
    Info,  T0: Import root directory is './'
    Warn,  T0: Ignored file of unknown type: 3D/3dmodel.model
    Warn,  T0: Ignored file of unknown type: 3D/Texture/CMC_LOGO_COLOR.png
    Warn,  T0: Ignored file of unknown type: 3D/_rels/3dmodel.model.rels
    Warn,  T0: Ignored file of unsupported type CONTENT_TYPES_ARCHIVES[Content_Types].xml
    Debug, T0: 3D/3dmodel.model
    Debug, T0: UpdateImporterScale scale set: 1
    Debug, T0: ValidateDataStructureProcess begin
    Error, T0: Validation failed: aiTexture::achFormatHint contains non-lowercase letters
    munmap_chunk(): invalid pointer

    Other times the import succeeds but the imported data structure refers to an embedded texture with outrageously large dimensions, such as a height of 1,092,883,925 texels. Such results might also be a symptom of uninitialized data. An application that tried to process such a texture might appear to hang.

    I'll attempt to gather diagnostic data using ASAN.

  5. stephengold commented on Nov 23, 2023

    @stephengold
    Contributor

    The crashes in my application occur when aiReleaseImport() is called. Since the assimp tool never releases the data structure, it does not crash.

    I modified Info.cpp to release the data structure before it returns:

    --- a/tools/assimp_cmd/Info.cpp
    +++ b/tools/assimp_cmd/Info.cpp
    @@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     #include <cstdio>
     #include <iostream>
     #include <string>
    +#include <assimp/cimport.h>
     
     constexpr char AICMD_MSG_INFO_HELP_E[] =
             "assimp info <file> [-r] [-v]\n"
    @@ -399,6 +400,7 @@ int Assimp_Info(const char *const *params, unsigned int num) {
     
         if (silent) {
             printf("\n");
    +        aiReleaseImport(scene);
             return AssimpCmdError::Success;
         }
     
    @@ -507,5 +509,7 @@ int Assimp_Info(const char *const *params, unsigned int num) {
         PrintHierarchy(scene->mRootNode, "", verbose);
     
         printf("\n");
    +
    +    aiReleaseImport(scene);
         return AssimpCmdError::Success;
     }

    and obtained the following ASAN output:

    ==21369==ERROR: AddressSanitizer: heap-use-after-free on address 0x61a000000688 at pc 0x7f573c9fbd94 bp 0x7ffcdf1f9810 sp 0x7ffcdf1f9800
    READ of size 8 at 0x61a000000688 thread T0
        #0 0x7f573c9fbd93 in aiScene::~aiScene() /home/sgold/NetBeansProjects/ext/assimp/code/Common/Version.cpp:148
        #1 0x7f573c95b557 in Assimp::Importer::~Importer() /home/sgold/NetBeansProjects/ext/assimp/code/Common/Importer.cpp:191
        #2 0x55b591887f5a in main /home/sgold/NetBeansProjects/ext/assimp/tools/assimp_cmd/Main.cpp:247
        #3 0x7f573bea1d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
        #4 0x7f573bea1e3f in __libc_start_main_impl ../csu/libc-start.c:392
        #5 0x55b59185f5e4 in _start (/home/sgold/NetBeansProjects/ext/assimp/build/bin/assimp+0x185e4)
    
    0x61a000000688 is located 8 bytes inside of 1168-byte region [0x61a000000680,0x61a000000b10)
    freed by thread T0 here:
        #0 0x7f573e4b724f in operator delete(void*, unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:172
        #1 0x7f573c8d67a7 in aiReleaseImport /home/sgold/NetBeansProjects/ext/assimp/code/Common/Assimp.cpp:284
        #2 0x55b591894d24 in Assimp_Info(char const* const*, unsigned int) /home/sgold/NetBeansProjects/ext/assimp/tools/assimp_cmd/Info.cpp:513
        #3 0x55b591887de1 in main /home/sgold/NetBeansProjects/ext/assimp/tools/assimp_cmd/Main.cpp:222
        #4 0x7f573bea1d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    
    previously allocated by thread T0 here:
        #0 0x7f573e4b61e7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
        #1 0x7f573c92487b in Assimp::BaseImporter::ReadFile(Assimp::Importer*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Assimp::IOSystem*) /home/sgold/NetBeansProjects/ext/assimp/code/Common/BaseImporter.cpp:131
        #2 0x7f573c960680 in Assimp::Importer::ReadFile(char const*, unsigned int) /home/sgold/NetBeansProjects/ext/assimp/code/Common/Importer.cpp:709
        #3 0x55b59188aef1 in Assimp::Importer::ReadFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int) /home/sgold/NetBeansProjects/ext/assimp/include/assimp/Importer.hpp:670
        #4 0x55b591888375 in ImportModel(ImportData const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/sgold/NetBeansProjects/ext/assimp/tools/assimp_cmd/Main.cpp:307
        #5 0x55b5918937c3 in Assimp_Info(char const* const*, unsigned int) /home/sgold/NetBeansProjects/ext/assimp/tools/assimp_cmd/Info.cpp:345
        #6 0x55b591887de1 in main /home/sgold/NetBeansProjects/ext/assimp/tools/assimp_cmd/Main.cpp:222
        #7 0x7f573bea1d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    
    SUMMARY: AddressSanitizer: heap-use-after-free /home/sgold/NetBeansProjects/ext/assimp/code/Common/Version.cpp:148 in aiScene::~aiScene()
    Shadow bytes around the buggy address:
      0x0c347fff8080: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c347fff8090: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c347fff80a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c347fff80b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c347fff80c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
    =>0x0c347fff80d0: fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c347fff80e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c347fff80f0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c347fff8100: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c347fff8110: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c347fff8120: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
    Shadow byte legend (one shadow byte represents 8 application bytes):
      Addressable:           00
      Partially addressable: 01 02 03 04 05 06 07 
      Heap left redzone:       fa
      Freed heap region:       fd
      Stack left redzone:      f1
      Stack mid redzone:       f2
      Stack right redzone:     f3
      Stack after return:      f5
      Stack use after scope:   f8
      Global redzone:          f9
      Global init order:       f6
      Poisoned by user:        f7
      Container overflow:      fc
      Array cookie:            ac
      Intra object redzone:    bb
      ASan internal:           fe
      Left alloca redzone:     ca
      Right alloca redzone:    cb
      Shadow gap:              cc
    ==21369==ABORTING
  6. stephengold commented on Nov 23, 2023

    @stephengold
    Contributor

    I wrote a test application (in Java) that imports "truck.3mf" 40 times and prints the dimensions of the embedded texture (and does not release the scene data structure). Sometimes the dimensions are correct, but mostly not.
    Here is typical output:

    width = 54813, height = 0
    width = 54813, height = 0
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 54813, height = 0
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = -1006631808, height = 32710
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539
    width = 12, height = 543583539

    I believe the correct dimensions are width = 54813, height = 0.

  7. kimkulling commented on Nov 27, 2023

    @kimkulling
    Member

    Hi, thanks a lot for the great analysis. I guess the detais of the embedded textures are broken. I need to check that.

  8. tellypresence commented on May 14, 2025

    @tellypresence
    CollaboratorAuthor

    3MF issues tracked via epic #6180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3MFBug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions