{"record":{"id":"6e8af4bee89865f8","repo":"gchq/CyberChef","slug":"size-must-be-greater-than-0","errorCode":null,"errorMessage":"Size must be greater than 0","messagePattern":"Size must be greater than 0","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/Shake.mjs","lineNumber":53,"sourceCode":"                \"name\": \"Size\",\n                \"type\": \"number\",\n                \"value\": 512\n            }\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const capacity = parseInt(args[0], 10),\n            size = args[1];\n        let algo;\n\n        if (size < 0)\n            throw new OperationError(\"Size must be greater than 0\");\n\n        switch (capacity) {\n            case 128:\n                algo = JSSHA3.shake128;\n                break;\n            case 256:\n                algo = JSSHA3.shake256;\n                break;\n            default:\n                throw new OperationError(\"Invalid size\");\n        }\n\n        return algo(input, size);\n    }\n\n}\n\nexport default Shake;","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/Shake.mjs#L35-L71","documentation":"Thrown by the Shake operation when the 'Size' argument (output length) is negative. SHAKE is an extendable-output function whose output size is user-controlled, and a negative size is meaningless. Note the guard checks size < 0, so a size of 0 passes this check but the message says 'greater than 0', a minor mismatch between message and guard.","triggerScenarios":"The 'Size' number argument is set to a negative value in the recipe. Can occur when a UI field is edited to a negative number or when a recipe is constructed programmatically with a negative size.","commonSituations":"Manual entry error in the Size field; recipe imported with a corrupted/typo'd size value; arithmetic that computes size from another field producing a negative result.","solutions":["Set the Size argument to a positive integer (default is 512).","If computing size dynamically, clamp it to a minimum of 1 before passing.","Be aware that 0 currently passes the guard but produces empty output - use a positive value."],"exampleFix":"// before\nrun(input, [\"256\", -16])\n// after\nrun(input, [\"256\", 512])","handlingStrategy":"validation","validationCode":"const capacity = parseInt(args[0], 10);\nconst size = args[1];\nif (typeof size !== \"number\" || size < 0) {\n  throw new Error(\"Shake size must be a non-negative integer.\");\n}\n// safe to invoke Shake (note: 0 currently passes but yields empty output)","typeGuard":"function isValidShakeSize(size) {\n  return typeof size === \"number\" && Number.isFinite(size) && size > 0;\n}","tryCatchPattern":"try {\n  chef.shake(input, { capacity: \"256\", size: 512 });\n} catch (e) {\n  // e.message indicates the size or capacity problem.\n}","preventionTips":["Keep Size at the default 512 unless you need a specific output length.","Clamp any computed size to a minimum of 1.","Remember only capacities 128 and 256 are valid."],"tags":["crypto","hash","sha3","argument-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}