{"record":{"id":"8f701832ea9246c1","repo":"gchq/CyberChef","slug":"levels-must-be-greater-than-0","errorCode":null,"errorMessage":"Levels must be greater than 0","messagePattern":"Levels must be greater than 0","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/MD6.mjs","lineNumber":58,"sourceCode":"                \"name\": \"Key\",\n                \"type\": \"string\",\n                \"value\": \"\"\n            }\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const [size, levels, key] = args;\n\n        if (size < 0 || size > 512)\n            throw new OperationError(\"Size must be between 0 and 512\");\n        if (levels < 0)\n            throw new OperationError(\"Levels must be greater than 0\");\n\n        return NodeMD6.getHashOfText(input, size, key, levels);\n    }\n\n}\n\nexport default MD6;\n","sourceCodeStart":40,"sourceCodeEnd":66,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/MD6.mjs#L40-L66","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Set Levels to 0 (auto) or a positive integer such as 64 (the default).","If you wanted node-md6 to choose the tree depth automatically, use 0.","Validate levels >= 0 before running; clamp negative values to 0 if 'auto' is acceptable."],"exampleFix":"// before\nmd6.run(input, [256, -1, '']);   // negative -> rejected\n\n// after\nmd6.run(input, [256, 0, '']);    // 0 = auto tree depth","handlingStrategy":"validation","validationCode":"function validMd6Levels(l) {\n  return Number.isInteger(l) && l >= 0;  // 0 = auto\n}\nif (!validMd6Levels(levels)) throw new Error('MD6 levels must be >= 0');","typeGuard":"function isMd6Levels(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 0;\n}","tryCatchPattern":null,"preventionTips":["Use 0 for auto tree depth or a positive integer like the default 64.","Clamp negative values to 0 before running.","Remember the guard is < 0, so 0 is allowed even though the message says 'greater than 0'."],"tags":["md6","hash","crypto","validation","argument-range"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}