{"record":{"id":"53701e11058e9568","repo":"BabylonJS/Babylon.js","slug":"deflate-invalid-block-type","errorCode":null,"errorMessage":"deflate: invalid block type","messagePattern":"deflate: invalid block type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/FBX/parsers/zlibInflate.ts","lineNumber":54,"sourceCode":"\r\n    let isFinalBlock = false;\r\n    while (!isFinalBlock) {\r\n        isFinalBlock = reader.readBits(1) === 1;\r\n        const blockType = reader.readBits(2);\r\n        switch (blockType) {\r\n            case 0:\r\n                inflateStoredBlock(reader, output);\r\n                break;\r\n            case 1:\r\n                inflateCompressedBlock(reader, output, getFixedLiteralLengthTree(), getFixedDistanceTree());\r\n                break;\r\n            case 2: {\r\n                const { literalLengthTree, distanceTree } = readDynamicTrees(reader);\r\n                inflateCompressedBlock(reader, output, literalLengthTree, distanceTree);\r\n                break;\r\n            }\r\n            default:\r\n                throw new Error(\"deflate: invalid block type\");\r\n        }\r\n    }\r\n\r\n    if (reader.byteOffset < input.byteLength - 4) {\r\n        throw new Error(\"zlib: trailing deflate data\");\r\n    }\r\n\r\n    output.finish();\r\n    const expectedAdler = ((input[input.byteLength - 4] << 24) | (input[input.byteLength - 3] << 16) | (input[input.byteLength - 2] << 8) | input[input.byteLength - 1]) >>> 0;\r\n    if (output.adler32() !== expectedAdler) {\r\n        throw new Error(\"zlib: adler32 mismatch\");\r\n    }\r\n\r\n    return output.bytes;\r\n}\r\n\r\nclass BitReader {\r\n    private bitBuffer = 0;\r","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/FBX/parsers/zlibInflate.ts#L36-L72","documentation":"DEFLATE block headers start with a 3-bit type: 0=stored, 1=fixed Huffman, 2=dynamic Huffman. inflateZlib throws 'deflate: invalid block type' when it reads bit pattern 3 (or otherwise invalid), meaning the compressed stream is corrupt or the bit position has desynchronized.","triggerScenarios":"Inflating an FBX compressed array whose deflate bitstream is corrupted, truncated mid-block, or whose start offset is wrong so the reader reads garbage as a block header; bit-level desync after a previously malformed block.","commonSituations":"Partially corrupted files (bad sectors, incomplete transfers); data sliced from the wrong byte offset; payloads recompressed or edited after export; a bug in an upstream compressor.","solutions":["Verify file integrity (checksum) and re-download/re-export the FBX","Check the compressed payload's start offset — zlib data begins at byte 2, and inflateZlib already sets this, so suspect file corruption first","Round-trip the data through a reference zlib inflate to see if it decompresses there","Catch and report as corrupt asset data rather than a parser bug"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// can't pre-validate deflate bits cheaply; validate container instead\nif (compressed.byteLength < 6 || !looksLikeZlib(compressed)) {\n  throw new Error('FBX compressed array container invalid');\n}","typeGuard":null,"tryCatchPattern":"try {\n  return inflateZlib(compressed, expectedLength);\n} catch (e) {\n  if ((e as Error).message === 'deflate: invalid block type') {\n    throw new Error('FBX compressed array bitstream is corrupt', { cause: e });\n  }\n  throw e;\n}","preventionTips":["Verify file hashes after transfer; deflate bit corruption is almost always file damage","Round-trip test suspect assets through a reference zlib inflate in CI","Avoid byte-level edits of compressed FBX payloads"],"tags":["zlib","deflate","corrupt-data","bitstream"],"backgroundTag":"corrupt-compressed-data","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}