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

glTF importer tries to use base64 text as file path #33796

Closed
qarmin opened this issue Nov 21, 2019 · 6 comments · Fixed by #42501 or #42504
Closed

glTF importer tries to use base64 text as file path #33796

qarmin opened this issue Nov 21, 2019 · 6 comments · Fixed by #42501 or #42504

Comments

@qarmin
Copy link
Contributor

qarmin commented Nov 21, 2019

Godot version:
3.2.beta.custom_build. 083d088

OS/device including version:
Ubuntu 19.10
Issue description:
After importing minimal project there is a lot of errors but I saw that Godot try to use encoded base64 text as path to files.

ERROR: get_file_as_array: Can't open file from path 'res://2.0/SimpleMorph/glTF-Embedded/data:application/gltf-buffer;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAA/AAAAPwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIC/AACAPwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIA/AACAPwAAAAA='.
   At: core/os/file_access.cpp:602.
ERROR: get_file_as_array: Can't open file from path 'res://2.0/SimpleMorph/glTF-Embedded/data:application/gltf-buffer;base64,AAAAAAAAgD8AAABAAABAQAAAgEAAAAAAAAAAAAAAAAAAAIA/AACAPwAAgD8AAIA/AAAAAAAAAAAAAAAA'.
   At: core/os/file_access.cpp:602.

or very long(> 50000 characters)

ERROR: _load: No loader found for resource: res://2.0/AlphaBlendModeTest/glTF-Embedded/data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAYAAAB/HSuDAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4gMQFzc3sTKNqAAAIABJREFUeNrs3Xl0VPXB/HPnS0zkwBZIAExLCKCtipHXFAQq6WAVCygsqq1WvVU1Kp9cO1Pq61a1Frbx2oVbRUkiq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MiQ/T6mqqqqzuUlJSUJ97OyshLu33fffUkb/z169NCoUaN07bXX6ve/718vv3/jXnfn+3cuXO/v1NpaWmTeza0x3soFDrs/o2xBwD253RJR5LhsBeT9BoZAAAAWt748eN16623as+ePXuXbdy4Uddee62mTZsmx3GSHjNlyhT9+9/TliWn5+vUaNG7fd1KioqtGPHDnXs2DFh+apVqxLuH3vssQn3Z86cmXD/z3/+s6677rqEiYXbb799v6+bl5enjRs37r2/du1adenSJWm9tWvXqra2tt5WwWAwYWKkqKhIeXl5Cets3ry53ufo1q2bPv300733v/zyS/Xq1Yt/iDgsvaiDuD4ntzZ3+5b/KwAAgNZmDmN33nlnnd/LhgwZYt566y2zZ88es2fPHrNs2TIzcuTIOtet6+R6+64zderUpHV+9KMfJazzm9/8pt6rFOzevTvh56+88kq9x9yPHz8+6RKAdRkxYkSDx/j36NEj4eczZ85MWufee++t93muv/76hJ9df/31bf7fF58uYAKAGxMAAACACQBLVFdXm0GDBh3097eJEyc26mR44XDYPPfccyYSiZitW7eaq6++OulEgZs2bUp4jpycnIR1brrpJrNjxw5TVlZmZs6caTp27FjvBvdrr72W9PMJEyaYL774wlRXV5t169aZiy++uMGTCRpjzNixYxN+npeXZ+bOnWt27txptm7dah588EGTlpZW7/OsW7fOeL3epH7Lli0zRUVFpqqqymzZssWsWLHC3HfffUmXNWQCAEwAcGMCAAAAgAmAJikpKTFnnHHGAX93u/DCC00kEmnUBEBDt9tuuy3pOSZMmFDvY9LT0+vd4HZdN+nSe4297WvhwoUNPsbn8zX4PHXtJXAg42ACAEwAcGMCAAAAgAmAJonFYmbKlCkmGAw2+J0tKyvL/OEPfzCu6zb6cninnXbafp9vwoQJdV4m8OuvvzadOnWq8zGBQMDMmzevwQ3mHTt2mNNPP73e3+c3v/lNoza8991rQftcwnDu3LmNep6pU6fWOVnABACYAODGBAAAAAATAK1m69at

Minimal reproduction project:
https://github.com/KhronosGroup/glTF-Sample-Models/archive/master.zip

@akien-mga
Copy link
Member

Minimal reproduction project:
https://github.com/KhronosGroup/glTF-Sample-Models/archive/master.zip

Welp... Here's a minimal reproduction project which doesn't weigh 850 MB ;)
glTF-import-bug.zip

(Includes the two assets referenced in the OP.)

@akien-mga akien-mga added this to the 4.0 milestone Oct 1, 2020
akien-mga added a commit to akien-mga/godot that referenced this issue Oct 2, 2020
…* MIME types

See KhronosGroup/glTF#944 for context on the
application/gltf-buffer MIME type.

The glTF 2.0 spec supports `image/jpeg` and `image/png` which can also be
base64-encoded in buffer URIs.

Fixes godotengine#33796.
@akien-mga akien-mga self-assigned this Oct 2, 2020
@akien-mga
Copy link
Member

For the reference, if you try to import https://github.com/KhronosGroup/glTF-Sample-Models after the fix, you'll now get a crash \o/ but it's unrelated to this glTF issue. There are actually some DAE files in the repo which trigger a crash in the Collada importer. I'll open an issue for that.

@akien-mga
Copy link
Member

I merged a bit too fast, after removing the Collada files there are still some glTF files which can fail. I'll make a follow up PR.

@akien-mga
Copy link
Member

akien-mga commented Oct 2, 2020

Alright, #42504 fixes the base64-related issues.

There's issues more among the ~250 glTF files of that Khronos repo, notably:

  • Some errors with the bufferView handling:
ERROR: Condition "buffer_end > bv.byte_length" is true. Returning: ERR_PARSE_ERROR
   at: _decode_buffer_view (editor/import/editor_scene_importer_gltf.cpp:597)
ERROR: Condition "buffer_end > bv.byte_length" is true. Returning: ERR_PARSE_ERROR
   at: _decode_buffer_view (editor/import/editor_scene_importer_gltf.cpp:597)
ERROR: Condition "buffer_end > bv.byte_length" is true. Returning: ERR_PARSE_ERROR
   at: _decode_buffer_view (editor/import/editor_scene_importer_gltf.cpp:597)
ERROR: Condition "array_len == 0" is true. Returning: ERR_INVALID_DATA
   at: mesh_create_surface_data_from_arrays (servers/rendering_server.cpp:803)
ERROR: Condition "err != OK" is true.
   at: add_surface_from_arrays (scene/resources/mesh.cpp:1118)
ERROR: Index p_idx = -1 is out of bounds (surfaces.size() = 0).
   at: surface_set_material (scene/resources/mesh.cpp:1214)
  • A segfault in the _parse_meshes function. It doesn't happen on the 3.2 branch, and I checked and it also happens before my changes in master, so it's not a regression from my fixes.
ERROR: FATAL: Index p_index = 2 is out of bounds (((Vector<T> *)(this))->_cowdata.size() = 2).
   at: operator[] (./core/vector.h:50)
handle_crash: Program crashed with signal 4
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /lib64/libc.so.6(+0x3a4e0) [0x7f871a68f4e0] (??:0)
[2] VectorWriteProxy<AABB>::operator[](int) (/home/akien/Projects/godot/godot.git/./core/vector.h:50 (discriminator 7))
[3] RasterizerStorageRD::mesh_add_surface(RID, RenderingServer::SurfaceData const&) (/home/akien/Projects/godot/godot.git/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp:2348 (discriminator 2))
[4] RenderingServerRaster::mesh_add_surface(RID, RenderingServer::SurfaceData const&) (/home/akien/Projects/godot/godot.git/servers/rendering/rendering_server_raster.h:245)
[5] RenderingServerWrapMT::mesh_add_surface(RID, RenderingServer::SurfaceData const&) (/home/akien/Projects/godot/godot.git/servers/rendering/rendering_server_wrap_mt.h:152 (discriminator 2))
[6] ArrayMesh::add_surface(unsigned int, Mesh::PrimitiveType, Vector<unsigned char> const&, int, Vector<unsigned char> const&, int, AABB const&, Vector<Vector<unsigned char> > const&, Vector<AABB> const&, Vector<RenderingServer::SurfaceData::LOD> const&) (/home/akien/Projects/godot/godot.git/scene/resources/mesh.cpp:1107)
[7] ArrayMesh::add_surface_from_arrays(Mesh::PrimitiveType, Array const&, Array const&, Dictionary const&, unsigned int) (/home/akien/Projects/godot/godot.git/scene/resources/mesh.cpp:1128)
[8] EditorSceneImporterGLTF::_parse_meshes(EditorSceneImporterGLTF::GLTFState&) (/home/akien/Projects/godot/godot.git/editor/import/editor_scene_importer_gltf.cpp:1232 (discriminator 3))
[9] EditorSceneImporterGLTF::import_scene(String const&, unsigned int, int, List<String, DefaultAllocator>*, Error*) (/home/akien/Projects/godot/godot.git/editor/import/editor_scene_importer_gltf.cpp:3209)
[10] ResourceImporterScene::import(String const&, String const&, Map<StringName, Variant, Comparator<StringName>, DefaultAllocator> const&, List<String, DefaultAllocator>*, List<String, DefaultAllocator>*, Variant*) (/home/akien/Projects/godot/godot.git/editor/import/resource_importer_scene.cpp:1274)
[11] EditorFileSystem::_reimport_file(String const&) (/home/akien/Projects/godot/godot.git/editor/editor_file_system.cpp:1729)
[12] EditorFileSystem::reimport_files(Vector<String> const&) (/home/akien/Projects/godot/godot.git/editor/editor_file_system.cpp:1916 (discriminator 3))
[13] EditorFileSystem::_update_scan_actions() (/home/akien/Projects/godot/godot.git/editor/editor_file_system.cpp:561)
[14] EditorFileSystem::_notification(int) (/home/akien/Projects/godot/godot.git/editor/editor_file_system.cpp:1123)
[15] EditorFileSystem::_notificationv(int, bool) (/home/akien/Projects/godot/godot.git/editor/editor_file_system.h:106 (discriminator 14))
[16] Object::notification(int, bool) (/home/akien/Projects/godot/godot.git/core/object.cpp:808)
[17] SceneTree::_notify_group_pause(StringName const&, int) (/home/akien/Projects/godot/godot.git/scene/main/scene_tree.cpp:818)
[18] SceneTree::idle(float) (/home/akien/Projects/godot/godot.git/scene/main/scene_tree.cpp:447 (discriminator 2))
[19] Main::iteration() (/home/akien/Projects/godot/godot.git/main/main.cpp:2426)
[20] OS_LinuxBSD::run() (/home/akien/Projects/godot/godot.git/platform/linuxbsd/os_linuxbsd.cpp:240)
[21] godot-git(main+0x135) [0x1a9dd47] (/home/akien/Projects/godot/godot.git/platform/linuxbsd/godot_linuxbsd.cpp:60)
[22] /lib64/libc.so.6(__libc_start_main+0xea) [0x7f871a67bcda] (??:0)
[23] godot-git(_start+0x2a) [0x1a9db6a] (??:?)

I'll open separate issues for those (+ the Collada crash).

That's a crazily huge repo but it's a good testing resource for the glTF importer :)

@akien-mga
Copy link
Member

That's a crazily huge repo but it's a good testing resource for the glTF importer :)

Note: This repo also contains glTF 1.0 scenes that we don't support, so they raise errors too and fail importing. I'll see if we can gracefully recognize such files and ignore them.

@akien-mga akien-mga changed the title Godot try to use base64 text as file path glTF importer tries to use base64 text as file path Oct 5, 2020
@akien-mga
Copy link
Member

Some errors with the bufferView handling:

Welp, can't reproduce those today after reimporting everything from scratch.

A segfault in the _parse_meshes function. It doesn't happen on the 3.2 branch, and I checked and it also happens before my changes in master, so it's not a regression from my fixes.

I opened #42569 for this.

akien-mga added a commit to akien-mga/godot that referenced this issue Oct 5, 2020
The glTF 2.0 spec only makes `mimeType` mandatory for `bufferView` image data,
so the previous logic to handle URIs with base64-encoded images could fail if
`mimeType` is undefined.

The logic was documented and refactored to better handle the spec, notably:

- `uri` and `bufferView` are now mutually exclusive, and only the latter fails
  if `mimeType` is undefined.
- `uri` with a file path will now respect the `mimeType` if defined, and thus
  attempt loading the file with the specified format (even if its extension is
  not the one expected for this format). So we can support bad extensions (PNG
  data with `.jpg` extension) or custom ones (PNG data in `.img` file for
  example).
- `uri` with base64 encoded data will infer MIME type from `data:image/png` or
  `data:image/jpeg` if it was not documented in `mimeType` initially.
- `uri` with base64 encoded data, no `mimeType` and `application/octet-stream`
  or `application/gltf-buffer` will fall back to trying both PNG and JPEG
  loaders.

Fully fixes godotengine#33796 (and fixes up godotengine#42501).
akien-mga added a commit that referenced this issue Oct 5, 2020
…* MIME types

See KhronosGroup/glTF#944 for context on the
application/gltf-buffer MIME type.

The glTF 2.0 spec supports `image/jpeg` and `image/png` which can also be
base64-encoded in buffer URIs.

Fixes #33796.

(cherry picked from commit 34a5031)
akien-mga added a commit that referenced this issue Oct 5, 2020
The glTF 2.0 spec only makes `mimeType` mandatory for `bufferView` image data,
so the previous logic to handle URIs with base64-encoded images could fail if
`mimeType` is undefined.

The logic was documented and refactored to better handle the spec, notably:

- `uri` and `bufferView` are now mutually exclusive, and only the latter fails
  if `mimeType` is undefined.
- `uri` with a file path will now respect the `mimeType` if defined, and thus
  attempt loading the file with the specified format (even if its extension is
  not the one expected for this format). So we can support bad extensions (PNG
  data with `.jpg` extension) or custom ones (PNG data in `.img` file for
  example).
- `uri` with base64 encoded data will infer MIME type from `data:image/png` or
  `data:image/jpeg` if it was not documented in `mimeType` initially.
- `uri` with base64 encoded data, no `mimeType` and `application/octet-stream`
  or `application/gltf-buffer` will fall back to trying both PNG and JPEG
  loaders.

Fully fixes #33796 (and fixes up #42501).

(cherry picked from commit 2e99d0b)
MarcusElg pushed a commit to MarcusElg/godot that referenced this issue Oct 19, 2020
…* MIME types

See KhronosGroup/glTF#944 for context on the
application/gltf-buffer MIME type.

The glTF 2.0 spec supports `image/jpeg` and `image/png` which can also be
base64-encoded in buffer URIs.

Fixes godotengine#33796.
MarcusElg pushed a commit to MarcusElg/godot that referenced this issue Oct 19, 2020
The glTF 2.0 spec only makes `mimeType` mandatory for `bufferView` image data,
so the previous logic to handle URIs with base64-encoded images could fail if
`mimeType` is undefined.

The logic was documented and refactored to better handle the spec, notably:

- `uri` and `bufferView` are now mutually exclusive, and only the latter fails
  if `mimeType` is undefined.
- `uri` with a file path will now respect the `mimeType` if defined, and thus
  attempt loading the file with the specified format (even if its extension is
  not the one expected for this format). So we can support bad extensions (PNG
  data with `.jpg` extension) or custom ones (PNG data in `.img` file for
  example).
- `uri` with base64 encoded data will infer MIME type from `data:image/png` or
  `data:image/jpeg` if it was not documented in `mimeType` initially.
- `uri` with base64 encoded data, no `mimeType` and `application/octet-stream`
  or `application/gltf-buffer` will fall back to trying both PNG and JPEG
  loaders.

Fully fixes godotengine#33796 (and fixes up godotengine#42501).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment