{"record":{"id":"e7f73f03f802b0a5","repo":"BabylonJS/Babylon.js","slug":"context-unexpected-end-of-input","errorCode":null,"errorMessage":"${context}: unexpected end of input","messagePattern":"(.+?): unexpected end of input","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/FBX/parsers/fbxBinaryParser.ts","lineNumber":256,"sourceCode":"        case \"boolean[]\":\r\n            value = arrayData;\r\n            break;\r\n        case \"int64[]\":\r\n            value = readInt64ArrayData(arrayData);\r\n            break;\r\n        default:\r\n            throw new Error(`Unexpected array type: ${type}`);\r\n    }\r\n\r\n    return {\r\n        property: { type, value },\r\n        nextOffset: offset + compressedLength,\r\n    };\r\n}\r\n\r\nfunction ensureRange(bytes: Uint8Array, offset: number, byteLength: number, limit: number, context: string): void {\r\n    if (offset < 0 || byteLength < 0 || offset + byteLength > limit || offset + byteLength > bytes.byteLength) {\r\n        throw new Error(`${context}: unexpected end of input`);\r\n    }\r\n}\r\n\r\nfunction readUint64AsNumber(view: DataView, offset: number): number {\r\n    const low = view.getUint32(offset, true);\r\n    const high = view.getUint32(offset + 4, true);\r\n    return high * 0x100000000 + low;\r\n}\r\n\r\nfunction readInt64AsNumber(view: DataView, offset: number): number {\r\n    const low = view.getUint32(offset, true);\r\n    const high = view.getInt32(offset + 4, true);\r\n    return high * 0x100000000 + low;\r\n}\r\n\r\nfunction readInt64ArrayData(arrayData: Uint8Array): Float64Array {\r\n    const view = new DataView(arrayData.buffer, arrayData.byteOffset, arrayData.byteLength);\r\n    const values = new Float64Array(arrayData.byteLength / 8);\r","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/FBX/parsers/fbxBinaryParser.ts#L238-L274","documentation":"ensureRange is the FBX binary parser's bounds check: it verifies that reading byteLength bytes at offset stays within the parse limit and the input buffer. If not, it throws '<context>: unexpected end of input', where context names which parse step (parseNode/parseProperty/parseArrayProperty) ran past the available bytes.","triggerScenarios":"Any nested record whose declared length or offset reaches past bytes.byteLength or the parent node limit: a truncated file, a node header advertising more bytes than exist, or an offset computed from a bad earlier field landing beyond the buffer.","commonSituations":"Incomplete downloads of .fbx files; files cut off mid-write; corrupt container unzips; a progress/limit parameter passed incorrectly when parsing a sub-region; reading an FBX embedded inside another file with wrong offsets.","solutions":["Verify the file is fully downloaded (size/hash check) and re-download if truncated","Check that any byte offset/limit you pass into the parser points at the real start of the FBX binary section","Validate the file with a reference FBX reader; if it fails there too, the file is corrupt — re-export it","If parsing embedded FBX blobs, confirm the container's length field is correct","Wrap parsing in try-catch and surface a user-facing 'corrupt or incomplete FBX file' message"],"exampleFix":"// before\nconst bytes = fs.readFileSync(partialPath); parse(bytes);\n// after\nif (actualHash !== expectedHash) throw new Error('FBX download incomplete; re-fetching');\nconst bytes = fs.readFileSync(fullyDownloadedPath); parse(bytes);","handlingStrategy":"validation","validationCode":"// caller-side check before parsing\nif (bytes.byteLength < MIN_FBX_HEADER_LENGTH || bytes.byteLength < declaredFileSize) {\n  throw new Error('FBX file truncated or empty');\n}","typeGuard":"function hasSufficientBytes(bytes: Uint8Array, offset: number, need: number): boolean {\n  return offset >= 0 && offset + need <= bytes.byteLength;\n}","tryCatchPattern":"try {\n  scene = parseFbxBinary(bytes);\n} catch (e) {\n  if ((e as Error).message.endsWith('unexpected end of input')) {\n    throw new Error('FBX file is incomplete or corrupted — re-download it', { cause: e });\n  }\n  throw e;\n}","preventionTips":["Always verify file size/hash after download before parsing","Never parse a buffer shorter than its declared length","When parsing embedded blobs, validate container offsets and lengths first"],"tags":["fbx","binary-parsing","bounds-check","truncated-data"],"backgroundTag":"unexpected-end-of-input","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}