KhronosGroup / glTF-Validator

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

npm version gltf-validator is not able to detect glb with GLB_INVALID_MAGIC error #211

Closed jiangjiangcau closed 1 month ago

jiangjiangcau commented 1 year ago

I followed the instruction in https://www.npmjs.com/package/gltf-validator to validate a GLB file. This file has invalid magic value, which can be detected by https://github.khronos.org/glTF-Validator/. But https://www.npmjs.com/package/gltf-validator cannot detect it. Does NPM version miss anything?

lexaknyazev commented 4 months ago

There's a subtle difference in how the web (online) and npm frontends operate.

The web version checks the file extension and if it's .glb proceeds with GLB format checks.

The validateBytes function from the npm version does not know the file extension and tries to guess the file format based on the first byte. If that byte is g, the file is assumed to be GLB; if that byte is one of the valid leading JSON bytes, the file is assumed to be glTF JSON. If the first byte is unrecognized, validateBytes completes with an error instead of the validation report.