BabylonJS/Babylon.js · error · Error
Truncated binary FBX header
Error message
Truncated binary FBX header
What it means
A binary FBX file must contain at least a 27-byte header (21-byte magic, 2 padding bytes, 4-byte version uint32). If the ArrayBuffer is shorter than HEADER_SIZE the file is truncated and no version or node data can be read, so the parser throws.
Source
Thrown at packages/dev/loaders/src/FBX/parsers/fbxBinaryParser.ts:22
const FBX_MAGIC = "Kaydara FBX Binary \0";
const HEADER_SIZE = 27; // 21 magic + 2 padding + 4 version uint32
/**
* Parse a binary FBX file into an FBXDocument.
* Supports FBX versions 7.0–7.7 (v7.5+ uses 64-bit node headers).
*/
export function parseBinaryFBX(buffer: ArrayBuffer): FBXDocument {
const view = new DataView(buffer);
const bytes = new Uint8Array(buffer);
// Validate magic
const magic = decodeASCII(bytes, 0, 21);
if (magic !== FBX_MAGIC) {
throw new Error("Not a valid binary FBX file");
}
if (buffer.byteLength < HEADER_SIZE) {
throw new Error("Truncated binary FBX header");
}
const version = view.getUint32(23, true);
// v7.5+ uses 64-bit offsets in node records
const is64Bit = version >= 7500;
const nodes: FBXNode[] = [];
let offset = HEADER_SIZE;
while (offset < buffer.byteLength) {
const result = parseNode(view, bytes, offset, is64Bit, buffer.byteLength);
if (result === null) {
break; // null sentinel node
}
nodes.push(result.node);
offset = result.endOffset;
}
View on GitHub (pinned to 0592b347b8)
Solutions
- Check `buffer.byteLength >= 27` before parsing; re-fetch the file if shorter
- Re-download/re-upload the asset — the file on disk may itself be truncated
- Ensure the whole file is read into the buffer (await full read, use Blob.arrayBuffer()/fs full read)
- If handling untrusted input, treat this as invalid input and surface a user-facing 'corrupt file' message
Example fix
// before
parseBinaryFBX(await partialChunk.arrayBuffer());
// after
const buf = await file.arrayBuffer();
if (buf.byteLength < 27) throw new Error("FBX file is truncated");
parseBinaryFBX(buf); Defensive patterns
Strategy: validation
Validate before calling
function hasFbxHeader(buf) {
return buf instanceof ArrayBuffer && buf.byteLength >= 27;
}
if (!hasFbxHeader(buffer)) throw new Error("FBX buffer too small/truncated"); Type guard
function isPlausibleFbxBuffer(buf) {
return buf instanceof ArrayBuffer && buf.byteLength >= 27;
} Try / catch
try {
const doc = parseBinaryFBX(buffer);
} catch (e) {
if (e.message === "Truncated binary FBX header") {
console.error(`Buffer is ${buffer.byteLength} bytes; need ≥27 — re-fetch the file`);
} else throw e;
} Prevention
- Always check byteLength before creating a DataView
- Await full reads (Blob.arrayBuffer, complete fs reads) — never pass stream chunks
- Verify downloaded size against Content-Length or expected size
- Guard test fixtures against empty/placeholder files
When it happens
Trigger: Calling the binary FBX parse (via `_parseFromArrayBuffer`/`doc`) with an ArrayBuffer of byteLength < 27 — e.g. an empty buffer, a partially downloaded file, or a tiny placeholder file.
Common situations: Incomplete uploads/downloads; file reads aborted mid-way producing zero-length buffers; test fixtures containing stub files; streaming code that passes a partial chunk instead of the whole file.
Related errors
- ASCII FBX array declared ${count} values but parsed ${values
- Not a valid binary FBX file
- Invalid FBX node end offset ${endOffset} at offset ${offset}
- Invalid FBX property list length for node '${name}' at offse
- Invalid FBX child node end offset ${child.endOffset} at offs
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/f6b8447e4afc3950.
Report an issue: GitHub.