GLTFFileLoader.loadFile does not call onError callback for files with less than 20 characters

For corrupt GLB and GLTF files with less than 20 bytes, GLTFFileLoader.loadFile throws an unhandled exception instead of calling the onError callback. I was able to track the issue does to the construction of the Unt8Array in the following codeblock (starting on line 538). Fundamentally the issue is an out-of-bounds error resulting from the combination of byteOffset and byteLength being greater than the file length (in this case, 19).

            return this._loadFile(scene, fileOrUrl, (data) => {
                const arrayBuffer = data as ArrayBuffer;
                this._unpackBinaryAsync(new DataReader({
                    readAsync: (byteOffset, byteLength) => Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)),
                    byteLength: arrayBuffer.byteLength
                })).then((loaderData) => {
                    onSuccess(loaderData);
                }, onError);
            }, true, onError);

I’m happy to open a GitHub issue once this is validated. While most of the time this won’t be an issue, given the architecture of the loaders, it is nearly impossible to catch the error from the surface of the library so when a <= 19 character file is submitted, a crash is currently unpreventable.

Edit: Here is the file contents that I’ve been using for testing.

{
	'hello': '123'
}

Thanks in advance!

2 Likes

Seems like a bug to me. @bghgary , want to validate?

Sounds like a bug to me as well. It should only happen for GLBs though. glTFs shouldn’t go through this code path. Can you create a repro on a PG and submit an issue on GitHub?

3 Likes

Sure. Here’s the GitHub Issue: GLTFFileLoader.loadFile does not call onError callback for .GLB files with less than 20 characters · Issue #11052 · BabylonJS/Babylon.js · GitHub.

Looking forward to the fix!

2 Likes

The fix will be in the next nightly thanks @bghgary

1 Like