gchq/CyberChef · error · OperationError

Levels must be greater than 0

Error message

Levels must be greater than 0

What it means

Thrown by the MD6 hash operation when the 'Levels' argument (args[1]) is negative. Levels controls the depth of the MD6 Merkle tree (the number of parallel levels); run() rejects values below 0 at MD6.mjs:58. Note the condition is levels < 0 while the message says 'greater than 0' — so levels = 0 actually passes and is forwarded to node-md6 (which interprets 0 as auto). The default is 64.

Source

Thrown at src/core/operations/MD6.mjs:58

                "name": "Key",
                "type": "string",
                "value": ""
            }
        ];
    }

    /**
     * @param {string} input
     * @param {Object[]} args
     * @returns {string}
     */
    run(input, args) {
        const [size, levels, key] = args;

        if (size < 0 || size > 512)
            throw new OperationError("Size must be between 0 and 512");
        if (levels < 0)
            throw new OperationError("Levels must be greater than 0");

        return NodeMD6.getHashOfText(input, size, key, levels);
    }

}

export default MD6;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Set Levels to 0 (auto) or a positive integer such as 64 (the default).
  2. If you wanted node-md6 to choose the tree depth automatically, use 0.
  3. Validate levels >= 0 before running; clamp negative values to 0 if 'auto' is acceptable.

Example fix

// before
md6.run(input, [256, -1, '']);   // negative -> rejected

// after
md6.run(input, [256, 0, '']);    // 0 = auto tree depth
Defensive patterns

Strategy: validation

Validate before calling

function validMd6Levels(l) {
  return Number.isInteger(l) && l >= 0;  // 0 = auto
}
if (!validMd6Levels(levels)) throw new Error('MD6 levels must be >= 0');

Type guard

function isMd6Levels(v: unknown): v is number {
  return typeof v === 'number' && Number.isInteger(v) && v >= 0;
}

Prevention

When it happens

Trigger: Setting the Levels argument to any negative number (e.g. -1). Raised at MD6.mjs:57-58 before NodeMD6.getHashOfText. levels = 0 does NOT trigger this (the message wording is slightly looser than the guard).

Common situations: A recipe with a typo'd negative levels value; misinterpreting 'levels' as something that must be strictly positive and entering a sentinel like -1 to mean 'default'; loading a recipe exported with an invalid field.

Related errors


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