{"record":{"id":"081b03820b76877a","repo":"BabylonJS/Babylon.js","slug":"deflate-invalid-stored-block-length","errorCode":null,"errorMessage":"deflate: invalid stored block length","messagePattern":"deflate: invalid stored block length","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/FBX/parsers/zlibInflate.ts","lineNumber":303,"sourceCode":"        }\r\n        fixedLiteralLengthTree = new HuffmanTree(lengths);\r\n    }\r\n    return fixedLiteralLengthTree;\r\n}\r\n\r\nfunction getFixedDistanceTree(): HuffmanTree {\r\n    if (!fixedDistanceTree) {\r\n        fixedDistanceTree = new HuffmanTree(new Array<number>(32).fill(5));\r\n    }\r\n    return fixedDistanceTree;\r\n}\r\n\r\nfunction inflateStoredBlock(reader: BitReader, output: OutputWriter): void {\r\n    reader.alignToByte();\r\n    const length = reader.readUint16LE();\r\n    const inverseLength = reader.readUint16LE();\r\n    if (((length ^ inverseLength) & 0xffff) !== 0xffff) {\r\n        throw new Error(\"deflate: invalid stored block length\");\r\n    }\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","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/FBX/parsers/zlibInflate.ts#L285-L321","documentation":"A stored (uncompressed, type-0) deflate block stores LEN and NLEN where NLEN must be the bitwise complement of LEN. This error is thrown when the one's-complement check fails, so the bytes being read as a stored-block header are not a valid stored block — typically the reader is not where it thinks it is, or the data is not deflate at all.","triggerScenarios":"inflateZlib encounters blockType 0 and inflateStoredBlock reads two uint16 LE values whose XOR is not 0xffff — the bitstream position is misaligned (wrong payload offset, or a previous block was parsed from wrong bytes) or the data is corrupt.","commonSituations":"Passing raw deflate (no zlib wrapper) or gzip data to inflateZlib; slicing an FBX array payload starting at the wrong byte; FBX files altered by a lossy transfer (text-mode FTP, encoding conversion).","solutions":["Verify the payload begins with a valid zlib header (CMF=0x78 etc.) — if not, you are feeding raw deflate or gzip","Check the compressed byte count in the FBX array property header is used as the slice length, not the uncompressed length","Compare with python zlib.decompress(payload) to confirm whether the payload itself is broken","Re-transfer the file in binary mode / re-export from the source tool"],"exampleFix":"// before\nconst raw = data.subarray(pos);            // includes adler32 of nothing / wrong span\n// after\nconst payload = data.subarray(pos, pos + compressedLen);\nconst out = inflateZlib(payload, uncompressedLen);","handlingStrategy":"validation","validationCode":"// Confirm zlib wrapper presence before inflating\nif (!(payload[0] === 0x78 || payload[0] === 0x08)) {\n  throw new Error(\"Payload does not look zlib-wrapped; check slicing\");\n}","typeGuard":"function hasZlibHeader(d: Uint8Array): d is Uint8Array & { length: number } {\n  return d.byteLength >= 2 && (d[0] & 0x0f) === 8 && ((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 stored block length\") {\n    throw new Error(\"Stored block LEN/NLEN mismatch — payload offset or format is wrong\", { cause: e });\n  }\n  throw e;\n}","preventionTips":["Verify the FBX encoding flag is 1 before inflating (encoding 0 is raw bytes)","Use the header's compressed byte count for the payload slice","Transfer files in binary mode; text-mode transfers corrupt binary FBX"],"tags":["deflate","stored-block","corrupt-data","fbx"],"backgroundTag":"invalid-stored-block-length","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}