{"record":{"id":"30a3016acb785bd6","repo":"gchq/CyberChef","slug":"size-must-be-between-0-and-512","errorCode":null,"errorMessage":"Size must be between 0 and 512","messagePattern":"Size must be between 0 and 512","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/MD6.mjs","lineNumber":56,"sourceCode":"            },\n            {\n                \"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":38,"sourceCodeEnd":66,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/MD6.mjs#L38-L66","documentation":"Thrown by the MD6 hash operation when the 'Size' argument (args[0]) is outside 0–512. MD6 produces a variable-length digest and the node-md6 library expects the bit length; run() rejects any size below 0 or above 512 at MD6.mjs:56. The default is 256. Size is measured in bits.","triggerScenarios":"Setting the Size argument to a negative number or any value greater than 512 — e.g. 1024, -1, 0 is allowed. Raised at MD6.mjs:55-56 before NodeMD6.getHashOfText is called.","commonSituations":"Confusing bit length with byte length (entering 2048 thinking bytes); copying a recipe that set a non-standard size; setting 0 expecting 'no hash' (0 is actually permitted and yields a zero-length digest).","solutions":["Set Size to a value between 0 and 512 inclusive, expressed in bits (common: 256, 224, 512).","If you entered a byte count, multiply-check: MD6 size is in bits, so use e.g. 256 not 32.","Validate 0 <= size <= 512 before running."],"exampleFix":"// before\nmd6.run(input, [1024, 64, '']);   // size too large\n\n// after\nmd6.run(input, [256, 64, '']);     // 256-bit digest","handlingStrategy":"validation","validationCode":"function validMd6Size(s) {\n  return Number.isInteger(s) && s >= 0 && s <= 512;\n}\nif (!validMd6Size(size)) throw new Error('MD6 size must be 0..512 bits');","typeGuard":"function isMd6Size(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 512;\n}","tryCatchPattern":null,"preventionTips":["Treat Size as bits, not bytes (256, not 32).","Clamp Size into 0..512 before running.","Prefer standard digest sizes (224/256/512)."],"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"}