Description:
In PlatformDependent/WebGL/UnityLoader/FetchWithProgress.js line 31, lengthComputable is computed as:
var lengthComputable = typeof response.headers.get('Content-Length') !== "undefined";
Headers.get() returns null when a header is absent, and typeof null is "object", which is never "undefined". This means lengthComputable is always true, regardless of whether the Content-Length header exists.
Consequences:
- The warning on line 39 about missing Content-Length never fires.
- estimateContentLength receives lengthComputable = true and calls parseInt(null), which returns NaN. This propagates through Math.round(NaN * 2) into new Uint8Array(NaN), creating a zero-length buffer. Every chunk then overflows into trailingChunks, forcing a full reallocation
at the end — defeating the purpose of the pre-allocation optimization.
Additionally, on line 138, init.enableStreamingDownload is accessed without null-checking init, which can throw a TypeError if init is null or undefined.
Fix: Change the check to response.headers.get('Content-Length') !== null, and guard the init access on line 138 with init && init.enableStreamingDownload.
Severity: High — causes degraded download performance for all WebGL asset loads where Content-Length is absent, and potential TypeError crash when init is not provided.
Component: WebGL / UnityLoader