KhronosGroup / glTF-Validator

Tool to validate glTF assets.
Apache License 2.0
372 stars 63 forks source link

Invalid JSON data. Parser output: FormatException: Unexpected extension byte #226

Closed Sembiance closed 4 months ago

Sembiance commented 4 months ago

Using the latest code checked out and built this morning, when running gltf_validator --stdout font.glb on the file in the attached font.zip yields the following error:

{
    "uri": "font.glb",
    "mimeType": "model/gltf-binary",
    "validatorVersion": "2.0.0-dev.3.10",
    "issues": {
        "numErrors": 1,
        "numWarnings": 0,
        "numInfos": 0,
        "numHints": 0,
        "messages": [
            {
                "code": "INVALID_JSON",
                "message": "Invalid JSON data. Parser output: FormatException: Unexpected extension byte (at offset 429)",
                "severity": 0,
                "pointer": ""
            }
        ],
        "truncated": false
    }
}

Model loads up ok in modelviewer.dev and assimp info font.glb crrectly returns information about the file.

lexaknyazev commented 4 months ago

Although the error message could be more helpful, the file is technically incorrect.

The nodes array contains the following element:

{"name":"�","mesh":63}

The relevant bytes in the file are:

0x22 0x6E 0x61 0x6D 0x65 0x22 0x3A 0x22 0xA3 0x22
   "    n    a    m    e    "    :    "    �    "

Assuming that the name value is supposed to be "£" (0xA3 in Latin-1), the corresponding UTF-8 bytes should have been 0xC2 0xA3.

Sembiance commented 4 months ago

The nodes array contains the following element: Assuming that the name value is supposed to be "£" (0xA3 in Latin-1), the corresponding UTF-8 bytes should have been 0xC2 0xA3.

Ahh, gtocha. I don't have any control over how the GLB file is generated, I'm just using glTF-Validator to determine if I have a renderable GLB or not.

Although the error message could be more helpful, the file is technically incorrect.

Aye. It would be awesome if:

  1. Invalid character data for a name field would show up with a more useful message
  2. The info property should still show, detailing the other properties of the model

Basically I feel that a single invalid character in a name field should not cause the validation tool to not output any other info at all about the file. User entered data in fields like name are more likely to have invalid data and I don't feel like that should prevent the validator from parsing all the more 'mechanical' parts of the file regarding the model itself, geometry, etcc

lexaknyazev commented 4 months ago

As UTF-8 decoding happens before JSON parsing, the validation tool cannot attribute incorrect octet sequences to specific properties; other software may have similar behavior. For example, the file cannot be imported into Blender and does not render in iOS glTF Viewer.

Even if loading succeeds, as in three.js (on which the model viewer is based on), the node shows its name as � instead of £.

I don't have any control over how the GLB file is generated

Consider reporting this error to the tool used for generating the asset.

Sembiance commented 4 months ago

That makes sense. Thanks.