diff options
author | Mario Liebisch <mario.liebisch@gmail.com> | 2023-01-19 09:42:57 +0100 |
---|---|---|
committer | Mario Liebisch <mario.liebisch@gmail.com> | 2023-01-19 09:49:28 +0100 |
commit | 9ba5d31141ae5d93ec0e1b7e46e65ff11839b582 (patch) | |
tree | 484983db7aa6f885b8ad7e74bb0cf47267f00390 /editor | |
parent | d93b66ad4d6b1dae42cc318c16224d03bd1a1472 (diff) |
Avoid importing MSVC obj files
Currently Godot tries to import any file with the extension "obj" as a
Wavefront OBJ model in text format.
This will fail and potentially crash the editor, if the obj file is
actually binary, like a MSVC build artifact/object file.
While the COFF header at the start of the obj file is subject to change,
this change should cover all potential/typical target machines possible
right now.
This fixes #71656.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/import/resource_importer_obj.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index ad6d41e10c..3dd01754a3 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -206,6 +206,20 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_ Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ); ERR_FAIL_COND_V_MSG(f.is_null(), ERR_CANT_OPEN, vformat("Couldn't open OBJ file '%s', it may not exist or not be readable.", p_path)); + // Avoid trying to load/interpret potential build artifacts from Visual Studio (e.g. when compiling native plugins inside the project tree) + // This should only match, if it's indeed a COFF file header + // https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types + const int first_bytes = f->get_16(); + static const Vector<int> coff_header_machines{ + 0x0, // IMAGE_FILE_MACHINE_UNKNOWN + 0x8664, // IMAGE_FILE_MACHINE_AMD64 + 0x1c0, // IMAGE_FILE_MACHINE_ARM + 0x14c, // IMAGE_FILE_MACHINE_I386 + 0x200, // IMAGE_FILE_MACHINE_IA64 + }; + ERR_FAIL_COND_V_MSG(coff_header_machines.find(first_bytes) != -1, ERR_FILE_CORRUPT, vformat("Couldn't read OBJ file '%s', it seems to be binary, corrupted, or empty.", p_path)); + f->seek(0); + Ref<ArrayMesh> mesh; mesh.instantiate(); |