{"record":{"id":"e534e7ac93ad0ea8","repo":"BabylonJS/Babylon.js","slug":"deflate-invalid-literal-length-symbol","errorCode":null,"errorMessage":"deflate: invalid literal/length symbol","messagePattern":"deflate: invalid literal/length symbol","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/FBX/parsers/zlibInflate.ts","lineNumber":322,"sourceCode":"    }\r\n\r\n    for (let i = 0; i < length; i++) {\r\n        output.writeByte(reader.readByte());\r\n    }\r\n}\r\n\r\nfunction inflateCompressedBlock(reader: BitReader, output: OutputWriter, literalLengthTree: HuffmanTree, distanceTree: HuffmanTree): void {\r\n    while (true) {\r\n        const symbol = literalLengthTree.decode(reader);\r\n        if (symbol < 256) {\r\n            output.writeByte(symbol);\r\n            continue;\r\n        }\r\n        if (symbol === 256) {\r\n            return;\r\n        }\r\n        if (symbol > 285) {\r\n            throw new Error(\"deflate: invalid literal/length symbol\");\r\n        }\r\n\r\n        const lengthIndex = symbol - 257;\r\n        const length = LENGTH_BASE[lengthIndex] + reader.readBits(LENGTH_EXTRA_BITS[lengthIndex]);\r\n        const distanceSymbol = distanceTree.decode(reader);\r\n        if (distanceSymbol > 29) {\r\n            throw new Error(\"deflate: invalid distance symbol\");\r\n        }\r\n        const distance = DISTANCE_BASE[distanceSymbol] + reader.readBits(DISTANCE_EXTRA_BITS[distanceSymbol]);\r\n        output.copy(distance, length);\r\n    }\r\n}\r\n\r\nfunction readDynamicTrees(reader: BitReader): {\r\n    literalLengthTree: HuffmanTree;\r\n    distanceTree: HuffmanTree;\r\n} {\r\n    const literalLengthCount = reader.readBits(5) + 257;\r","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/FBX/parsers/zlibInflate.ts#L304-L340","documentation":"In deflate, literal/length symbols are valid in 0-285; symbols 286 and 287 exist in the fixed table's 288-symbol space but are illegal. This error is thrown when the Huffman decoder returns a symbol >285, meaning the bitstream encoded an invalid code — a strong sign the data does not match the tree or is corrupt.","triggerScenarios":"inflateCompressedBlock, while decoding a type-1 (fixed) or type-2 (dynamic) block for an FBX compressed array, gets symbol 286/287 from literalLengthTree.decode(reader) — corrupt bits, or fixed-block decoding applied to data that isn't fixed-Huffman deflate.","commonSituations":"Payload that is gzip (header differs, but if someone strips wrappers manually) or otherwise not the format expected; truncated streams decoding leftover padding bits as codes; hand-crafted or tool-broken FBX files.","solutions":["Validate the payload independently with python zlib.decompress to isolate data corruption vs parsing bugs","Ensure the FBX array's 'Encoding' field is 1 (zlib) before calling inflateZlib — Encoding 0 data is uncompressed and will decode as garbage","Re-export the FBX from the DCC tool","Check the offset used to slice the payload matches the reader position after the property header"],"exampleFix":"// before: inflating regardless of encoding flag\nconst out = inflateZlib(payload, expectedLen);\n// after\nconst out = encoding === 1 ? inflateZlib(payload, expectedLen) : payload;","handlingStrategy":"validation","validationCode":"if (fbxArray.encoding !== 1) {\n  throw new Error(`Unexpected FBX array encoding ${fbxArray.encoding}; expected 1 (zlib)`);\n}\nif (payload.byteLength < 6) throw new Error(\"Payload too short to be zlib\");","typeGuard":"function isCompressedArray(p: { encoding: number; payload: Uint8Array }): boolean {\n  return p.encoding === 1 && p.payload.byteLength >= 6;\n}","tryCatchPattern":"try {\n  const arr = inflateZlib(payload, expectedLength);\n} catch (e) {\n  if (e instanceof Error && e.message === \"deflate: invalid literal/length symbol\") {\n    throw new Error(\"Corrupt FBX compressed array (invalid deflate symbol)\", { cause: e });\n  }\n  throw e;\n}","preventionTips":["Only call inflateZlib on encoding===1 arrays","Cross-check suspicious payloads with python zlib.decompress","Re-export assets that fail in reference tools too"],"tags":["deflate","huffman","corrupt-data","fbx"],"backgroundTag":"invalid-huffman-table","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}