gchq/CyberChef · error · Error
Invalid block type while parsing DEFLATE stream at pos ${str
Error message
Invalid block type while parsing DEFLATE stream at pos ${stream.position} What it means
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.
Source
Thrown at src/core/lib/FileSignatures.mjs:3892
break;
case 18:
repeat = 11 + stream.readBits(7, "le");
while (repeat--) lengthTable[i++] = 0;
prev = 0;
break;
default:
lengthTable[i++] = code;
prev = code;
break;
}
}
const dynamicLiteralTable = buildHuffmanTable(lengthTable.subarray(0, hlit));
const dynamicDistanceTable = buildHuffmanTable(lengthTable.subarray(hlit));
parseHuffmanBlock(stream, dynamicLiteralTable, dynamicDistanceTable);
} else {
throw new Error(`Invalid block type while parsing DEFLATE stream at pos ${stream.position}`);
}
}
// Consume final byte if it has not been fully consumed yet
if (stream.bitPos > 0)
stream.moveForwardsBy(1);
}
// Static length tables
const lengthExtraTable = [
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
];
const distanceExtraTable = [
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
];
/**View on GitHub (pinned to 4290ea7539)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
// DEFLATE validity cannot be cheaply pre-validated; use a reference inflate to sanity-check.
// Node-only sanity check:
// try { require("zlib").inflateSync(Buffer.from(bytes)); } catch (e) { /* not valid deflate */ } Try / catch
try {
extractDeflate(bytes, offset);
} catch (err) {
if (/Invalid block type while parsing DEFLATE/.test(err.message)) {
// not a valid DEFLATE stream; route elsewhere or re-acquire
} else throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid Huffman Code length while parsing DEFLATE block at p
- Invalid marker while parsing JPEG at pos ${stream.position}:
- Caught in probable infinite loop while parsing Huffman Block
- Unable to parse JPEG successfully
- Invalid recipe
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/1f95b5a91e7d7d4d.
Report an issue: GitHub.