{"record":{"id":"2bbdf2f27057464d","repo":"BabylonJS/Babylon.js","slug":"deflate-invalid-distance-symbol","errorCode":null,"errorMessage":"deflate: invalid distance symbol","messagePattern":"deflate: invalid distance symbol","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/FBX/parsers/zlibInflate.ts","lineNumber":329,"sourceCode":"function 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\n    const distanceCount = reader.readBits(5) + 1;\r\n    const codeLengthCount = reader.readBits(4) + 4;\r\n\r\n    const codeLengthLengths = new Array<number>(19).fill(0);\r\n    for (let i = 0; i < codeLengthCount; i++) {\r\n        codeLengthLengths[CODE_LENGTH_ORDER[i]] = reader.readBits(3);\r\n    }\r","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/FBX/parsers/zlibInflate.ts#L311-L347","documentation":"Distance symbols are valid in 0-29 in deflate. This error fires when distanceTree.decode returns a value above 29 (possible only with a fixed distance tree's 32-symbol space), i.e. the stream encoded an out-of-range distance code — the data is corrupt or being decoded with the wrong tree.","triggerScenarios":"inflateCompressedBlock decodes a length symbol, then distanceTree.decode(reader) returns 30 or 31 (fixed distance tree encodes 32 symbols of 5 bits each; the top two are illegal per RFC 1951).","commonSituations":"Decoding non-deflate bytes that happen to pass the zlib header check; corrupt FBX payload mid-block; wrong buffer slice causing bit misalignment so subsequent codes are garbage.","solutions":["Confirm with python zlib.decompress(payload) whether the payload is genuinely valid zlib — most often the file is corrupt","Verify the payload slice boundaries against the FBX array header's compressed byte count","Re-export/re-download the FBX asset","If reproducing from a specific file, dump the payload bytes around the failure offset to inspect whether it resembles compressed data at all"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// quick structural pre-check: zlib header + plausible size\nif (!(((payload[0] << 8) + payload[1]) % 31 === 0 && (payload[0] & 0x0f) === 8)) {\n  throw new Error(\"Not a zlib stream\");\n}","typeGuard":"function hasValidZlibHeader(d: Uint8Array): boolean {\n  return d.byteLength >= 2 && (d[0] & 0x0f) === 8 && d[0] >> 4 <= 7 && ((d[0] << 8) + d[1]) % 31 === 0;\n}","tryCatchPattern":"try {\n  const out = inflateZlib(payload, expectedLength);\n} catch (e) {\n  if (e instanceof Error && e.message === \"deflate: invalid distance symbol\") {\n    throw new Error(\"Invalid distance code in FBX compressed array — data corrupt\", { cause: e });\n  }\n  throw e;\n}","preventionTips":["Verify payload slice boundaries against the FBX array header","Keep binary assets checksum-verified in storage/CI","Test the same asset through a reference decompressor when diagnosing"],"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"}