{"record":{"id":"1f95b5a91e7d7d4d","repo":"gchq/CyberChef","slug":"invalid-block-type-while-parsing-deflate-stream-at","errorCode":null,"errorMessage":"Invalid block type while parsing DEFLATE stream at pos ${stream.position}","messagePattern":"Invalid block type while parsing DEFLATE stream at pos (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/lib/FileSignatures.mjs","lineNumber":3892,"sourceCode":"                        break;\n                    case 18:\n                        repeat = 11 + stream.readBits(7, \"le\");\n                        while (repeat--) lengthTable[i++] = 0;\n                        prev = 0;\n                        break;\n                    default:\n                        lengthTable[i++] = code;\n                        prev = code;\n                        break;\n                }\n            }\n\n            const dynamicLiteralTable = buildHuffmanTable(lengthTable.subarray(0, hlit));\n            const dynamicDistanceTable = buildHuffmanTable(lengthTable.subarray(hlit));\n\n            parseHuffmanBlock(stream, dynamicLiteralTable, dynamicDistanceTable);\n        } else {\n            throw new Error(`Invalid block type while parsing DEFLATE stream at pos ${stream.position}`);\n        }\n    }\n\n    // Consume final byte if it has not been fully consumed yet\n    if (stream.bitPos > 0)\n        stream.moveForwardsBy(1);\n}\n\n\n// Static length tables\nconst lengthExtraTable = [\n    0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0\n];\nconst distanceExtraTable = [\n    0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13\n];\n\n/**","sourceCodeStart":3874,"sourceCodeEnd":3910,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/FileSignatures.mjs#L3874-L3910","documentation":"Thrown inside the DEFLATE parser when the 2-bit block type (BTYPE) read from the stream is 0b11 (3). Per RFC 1951, BTYPE values are 00 (stored), 01 (fixed Huffman), 10 (dynamic Huffman); 11 is reserved and invalid. A plain Error, not OperationError.","triggerScenarios":"Parsing bytes that are not a DEFLATE stream (raw text, encrypted data, a different compression), a corrupted compressed payload, or a bit-aligned read that has drifted so the BTYPE bits decode as 3.","commonSituations":"Feeding non-deflate data into a PNG/ZIP/GZIP interior parser; truncated or bit-flipped compressed data; wrong offset into a container that skips the DEFLATE header.","solutions":["Confirm the input is actually DEFLATE-compressed (e.g. decompress with zlib/gunzip to sanity-check).","Verify the offset into the container points at a real DEFLATE block boundary.","If the data is corrupt, re-acquire the source rather than retrying the parser."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// DEFLATE validity cannot be cheaply pre-validated; use a reference inflate to sanity-check.\n// Node-only sanity check:\n// try { require(\"zlib\").inflateSync(Buffer.from(bytes)); } catch (e) { /* not valid deflate */ }","typeGuard":null,"tryCatchPattern":"try {\n  extractDeflate(bytes, offset);\n} catch (err) {\n  if (/Invalid block type while parsing DEFLATE/.test(err.message)) {\n    // not a valid DEFLATE stream; route elsewhere or re-acquire\n  } else throw err;\n}","preventionTips":["Confirm the data is DEFLATE-compressed before invoking the parser.","Use a canonical inflate (Node zlib) to verify integrity first.","Check the container offset points at a real DEFLATE block."],"tags":["deflate","compression","parsing","corruption","file-signatures"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}