{"record":{"id":"315ea5baf6ecbb41","repo":"BabylonJS/Babylon.js","slug":"deflate-missing-end-of-block-code","errorCode":null,"errorMessage":"deflate: missing end-of-block code","messagePattern":"deflate: missing end-of-block code","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/FBX/parsers/zlibInflate.ts","lineNumber":355,"sourceCode":"    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\n\r\n    const codeLengthTree = new HuffmanTree(codeLengthLengths);\r\n    const lengths = readCodeLengths(reader, codeLengthTree, literalLengthCount + distanceCount);\r\n    const literalLengthLengths = lengths.slice(0, literalLengthCount);\r\n    const distanceLengths = lengths.slice(literalLengthCount);\r\n\r\n    if (literalLengthLengths[256] === 0) {\r\n        throw new Error(\"deflate: missing end-of-block code\");\r\n    }\r\n\r\n    return {\r\n        literalLengthTree: new HuffmanTree(literalLengthLengths),\r\n        distanceTree: new HuffmanTree(distanceLengths, { allowEmpty: true }),\r\n    };\r\n}\r\n\r\nfunction readCodeLengths(reader: BitReader, codeLengthTree: HuffmanTree, count: number): number[] {\r\n    const lengths: number[] = [];\r\n    while (lengths.length < count) {\r\n        const symbol = codeLengthTree.decode(reader);\r\n        if (symbol <= 15) {\r\n            lengths.push(symbol);\r\n            continue;\r\n        }\r\n\r\n        let repeatLength: number;\r","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/FBX/parsers/zlibInflate.ts#L337-L373","documentation":"RFC 1951 requires every dynamic block's literal/length alphabet to define a nonzero code length for symbol 256 (end-of-block). This error is thrown in readDynamicTrees when the decoded lengths for the literal/length table assign zero length to symbol 256, so the block could never terminate — the header data is corrupt or was not produced by a compliant compressor.","triggerScenarios":"inflateZlib reads a type-2 dynamic block; readCodeLengths decodes HLIT+HDIST code lengths, and lengths.slice(0, literalLengthCount)[256] === 0, i.e. the end-of-block symbol has no code.","commonSituations":"Corrupt or truncated FBX compressed arrays (header bytes of the block lost); misaligned payload slicing reading garbage into the dynamic header; files produced by broken experimental compressors.","solutions":["Validate the payload with python zlib.decompress to confirm the data is bad vs the loader offsets being wrong","Check the FBX array header's compressed byte count and that the slice passed to inflateZlib starts at the zlib CMF byte","Re-export the asset from the source DCC tool","If many files from one pipeline fail, audit that pipeline's compression step"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Independent pre-validation of the payload\nimport { decompressSync } from \"fflate\"; // or any zlib impl\ntry { decompressSync(payload); } catch { throw new Error(\"FBX payload fails reference zlib decode — file corrupt\"); }","typeGuard":null,"tryCatchPattern":"try {\n  const out = inflateZlib(payload, expectedLength);\n} catch (e) {\n  if (e instanceof Error && e.message === \"deflate: missing end-of-block code\") {\n    throw new Error(\"FBX dynamic block lacks end-of-block symbol — corrupt stream\", { cause: e });\n  }\n  throw e;\n}","preventionTips":["If an independent zlib decoder also rejects the payload, the file is bad — re-export rather than patching the parser","Confirm the array property header (count, encoding, compressedLength) is parsed at the correct offsets","Detect truncation by comparing file size to the FBX footer/expected size"],"tags":["deflate","dynamic-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"}