{"record":{"id":"dc47d68d63f5f4cb","repo":"BabylonJS/Babylon.js","slug":"deflate-invalid-huffman-code","errorCode":null,"errorMessage":"deflate: invalid huffman code","messagePattern":"deflate: invalid huffman code","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/FBX/parsers/zlibInflate.ts","lineNumber":253,"sourceCode":"                return undefined;\r\n            }\r\n            const symbols = new Int16Array(1 << length);\r\n            symbols.fill(-1);\r\n            return symbols;\r\n        });\r\n        for (let symbol = 0; symbol < codeLengths.length; symbol++) {\r\n            const length = codeLengths[symbol];\r\n            if (length === 0) {\r\n                continue;\r\n            }\r\n            this.symbolsByLength[length]![nextCode[length]++] = symbol;\r\n        }\r\n        this.maxCodeLength = maxCodeLength;\r\n    }\r\n\r\n    public decode(reader: BitReader): number {\r\n        if (this.maxCodeLength === 0) {\r\n            throw new Error(\"deflate: invalid huffman code\");\r\n        }\r\n\r\n        let code = 0;\r\n        for (let length = 1; length <= this.maxCodeLength; length++) {\r\n            code = (code << 1) | reader.readBit();\r\n            const symbol = this.symbolsByLength[length]?.[code] ?? -1;\r\n            if (symbol >= 0) {\r\n                return symbol;\r\n            }\r\n        }\r\n        throw new Error(\"deflate: invalid huffman code\");\r\n    }\r\n}\r\n\r\nlet fixedLiteralLengthTree: HuffmanTree | undefined;\r\nlet fixedDistanceTree: HuffmanTree | undefined;\r\n\r\nfunction getFixedLiteralLengthTree(): HuffmanTree {\r","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/FBX/parsers/zlibInflate.ts#L235-L271","documentation":"HuffmanTree.decode throws immediately when the tree was built with maxCodeLength === 0, i.e. the tree has no symbols at all. For a distance tree this is allowed at build time (allowEmpty) but becomes fatal the moment the stream actually tries to decode a distance code from it, indicating the compressed stream references back-references while defining an empty distance alphabet.","triggerScenarios":"inflateCompressedBlock decodes a length symbol (257-285) and calls distanceTree.decode(reader), but the dynamic distance tree built from the block header was empty (all distance code lengths zero) — a stream that promises lengths but supplies no distance codes.","commonSituations":"Corrupt or non-standard FBX compressed arrays; a compressor bug emitting a length symbol without any distance tree; reading data from the wrong offset so garbage bits form a length symbol.","solutions":["Extract the array payload and test it with python's zlib.decompress to confirm whether the payload itself is valid deflate data","Verify the FBX array property header (encoding flag and compressed byte count) matches how the payload is sliced before inflateZlib","Re-export the asset from the DCC tool; an empty distance tree with a length symbol is never produced by compliant compressors","If this happens on previously-working files, check whether the loader version changed how payload offsets are computed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Ensure encoding flag is zlib before inflating\nif (fbxArray.encoding !== 1) throw new Error(\"Array is not zlib-compressed\");","typeGuard":"function isZlibEncoded(enc: number): enc is 1 {\n  return enc === 1;\n}","tryCatchPattern":"try {\n  const arr = parseArrayProperty(...);\n} catch (e) {\n  if (e instanceof Error && e.message === \"deflate: invalid huffman code\") {\n    console.error(\"FBX compressed array references distances with an empty distance tree — file is corrupt\");\n  }\n  throw e;\n}","preventionTips":["Validate the payload with an independent zlib implementation when diagnosing","Never construct inflateZlib input by manual byte math — read the header fields","Keep assets under checksum verification in storage"],"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"}