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: Fix parsing buffer data with application/gltf-buffer and image/* MIME types #42501

Merged

Conversation

akien-mga
Copy link
Member

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.


I made it more forgiving as I doubt we'll see situations where a URI starts with data: is meant to be loaded as a file path. But it should throw an error if it's not one of the supported MIME types so we can investigate further.

…* 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 added bug topic:import cherrypick:3.x Considered for cherry-picking into a future 3.x release labels Oct 2, 2020
@akien-mga akien-mga added this to the 4.0 milestone Oct 2, 2020
@akien-mga akien-mga merged commit 2d6e7df into godotengine:master Oct 2, 2020
@akien-mga akien-mga deleted the glTF-fix-parsing-base64-data branch October 2, 2020 10:48
@akien-mga
Copy link
Member Author

Note to self: this needs to be cherry-picked together with #42504 which properly fixes the issue, and fixes up some of the changes done here (no need to handle image MIME types for buffers).

akien-mga added a commit to akien-mga/godot that referenced this pull request 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
Copy link
Member Author

Cherry-picked for 3.2.4.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Oct 5, 2020
akien-mga added a commit that referenced this pull request 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 pull request 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

glTF importer tries to use base64 text as file path
1 participant