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

**URL:** https://forum.babylonjs.com/t/gltffileloader-loadfile-does-not-call-onerror-callback-for-files-with-less-than-20-characters/22669
**Category:** Bugs
**Created:** [July 29, 2021, 2:52am UTC](https://forum.babylonjs.com/t/gltffileloader-loadfile-does-not-call-onerror-callback-for-files-with-less-than-20-characters/22669 "2021-07-29T02:52:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sebastian.welsh](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@sebastian.welsh](https://forum.babylonjs.com/u/sebastian.welsh)
#### Post date: [July 29, 2021, 2:52am UTC](https://forum.babylonjs.com/t/gltffileloader-loadfile-does-not-call-onerror-callback-for-files-with-less-than-20-characters/22669/1 "2021-07-29T02:52:45Z")

</div>

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).

```auto
            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.

```auto
{
	'hello': '123'
}

```

Thanks in advance!

---

<div class="post-metadata">

### Author: ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)
#### Post date: [July 29, 2021, 8:57am UTC](https://forum.babylonjs.com/t/gltffileloader-loadfile-does-not-call-onerror-callback-for-files-with-less-than-20-characters/22669/2 "2021-07-29T08:57:19Z")

</div>

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

---

<div class="post-metadata">

### Author: ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)
#### Post date: [July 29, 2021, 3:27pm UTC](https://forum.babylonjs.com/t/gltffileloader-loadfile-does-not-call-onerror-callback-for-files-with-less-than-20-characters/22669/3 "2021-07-29T15:27:26Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![sebastian.welsh](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@sebastian.welsh](https://forum.babylonjs.com/u/sebastian.welsh)
#### Post date: [September 11, 2021, 10:30pm UTC](https://forum.babylonjs.com/t/gltffileloader-loadfile-does-not-call-onerror-callback-for-files-with-less-than-20-characters/22669/4 "2021-09-11T22:30:04Z")

</div>

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](https://github.com/BabylonJS/Babylon.js/issues/11052).

Looking forward to the fix!

---

<div class="post-metadata">

### Author: ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)
#### Post date: [September 14, 2021, 11:39pm UTC](https://forum.babylonjs.com/t/gltffileloader-loadfile-does-not-call-onerror-callback-for-files-with-less-than-20-characters/22669/5 "2021-09-14T23:39:36Z")

</div>

The fix will be in the next nightly thanks @bghgary
