gchq/CyberChef · error · Error

Caught in probable infinite loop while parsing Huffman Block

Error message

Caught in probable infinite loop while parsing Huffman Block

What it means

A safety valve in parseHuffmanBlock. A valid DEFLATE Huffman block terminates when code 256 (end-of-block) is read; the loop counts iterations and throws a plain Error after 10000 codes without termination. It guards against malformed streams that would otherwise spin the parser indefinitely.

Source

Thrown at src/core/lib/FileSignatures.mjs:3928

/**
 * Parses a Huffman Block given the literal and distance tables
 *
 * @param {Stream} stream
 * @param {Uint32Array} litTab
 * @param {Uint32Array} distTab
 */
function parseHuffmanBlock(stream, litTab, distTab) {
    let code;
    let loops = 0;
    while ((code = readHuffmanCode(stream, litTab))) {
        // console.log("Code: " + code + " (" + Utils.chr(code) + ") " + Utils.bin(code));

        // End of block
        if (code === 256) break;

        // Detect probably infinite loops
        if (++loops > 10000)
            throw new Error("Caught in probable infinite loop while parsing Huffman Block");

        // Literal
        if (code < 256) continue;

        // Length code
        stream.readBits(lengthExtraTable[code - 257], "le");

        // Dist code
        code = readHuffmanCode(stream, distTab);
        stream.readBits(distanceExtraTable[code], "le");
    }
}


/**
 * Builds a Huffman table given the relevant code lengths
 *
 * @param {Array} lengths

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Re-verify the compressed source integrity (CRC/check the container).
  2. Cross-check with a canonical inflate implementation (Node zlib) to see if the stream is valid at all.
  3. Discard the malformed input rather than attempting recovery.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  extractDeflate(bytes, offset);
} catch (err) {
  if (/probable infinite loop/.test(err.message)) {
    // corrupt Huffman stream; abandon this input
  } else throw err;
}

Prevention

When it happens

Trigger: Corrupted Huffman tables or scan data that emits literal codes forever; a malformed dynamic block whose end-of-block code can never be matched; crafted input designed to loop the parser (potential DoS vector).

Common situations: Bit-flipped compressed payload inside PNG/ZIP/GZIP; truncated table that mis-aligns subsequent reads; adversarial/crafted file fed to the extractor.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/860f0ddc7eb60214. Report an issue: GitHub.