{"record":{"id":"9612ad787a7c744e","repo":"gchq/CyberChef","slug":"invalid-size","errorCode":null,"errorMessage":"Invalid size","messagePattern":"Invalid size","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/Keccak.mjs","lineNumber":60,"sourceCode":"    run(input, args) {\n        const size = parseInt(args[0], 10);\n        let algo;\n\n        switch (size) {\n            case 224:\n                algo = JSSHA3.keccak224;\n                break;\n            case 384:\n                algo = JSSHA3.keccak384;\n                break;\n            case 256:\n                algo = JSSHA3.keccak256;\n                break;\n            case 512:\n                algo = JSSHA3.keccak512;\n                break;\n            default:\n                throw new OperationError(\"Invalid size\");\n        }\n\n        return algo(input);\n    }\n\n}\n\nexport default Keccak;\n","sourceCodeStart":42,"sourceCodeEnd":69,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/Keccak.mjs#L42-L69","documentation":"Thrown by Keccak when the size argument does not match one of {224, 256, 384, 512}. The size comes from a dropdown (option) bound to those four values, so in normal UI use this is unreachable; it fires only when parseInt(args[0], 10) yields something else - e.g. a hand-edited recipe with an out-of-list value, or args[0] undefined/non-numeric (parseInt(undefined) is NaN).","triggerScenarios":"A recipe JSON edited to set Size to '1024' or ''. Programmatic API call passing a size string not in the allowed set. args[0] missing so parseInt returns NaN, which matches no case and hits default.","commonSituations":"Sharing/importing a recipe that was hand-tweaked. Building a recipe programmatically and setting an invalid option. Migration introducing a new size value not reflected in the switch.","solutions":["Use one of the supported sizes: 224, 256, 384, or 512.","When building recipes programmatically, validate args[0] against ['224','256','384','512'] before running.","Re-select the Size from the dropdown to reset a corrupt value.","If a new Keccak size is needed, add both the option value and a matching case branch."],"exampleFix":"// before: hand-edited recipe size\nchef.Keccak(data, ['1024']); // parseInt -> NaN -> default\n// after: supported size\nchef.Keccak(data, ['512']);","handlingStrategy":"validation","validationCode":"const KECCAK_SIZES = new Set([224, 256, 384, 512]);\nfunction ensureKeccakSize(arg) {\n  const size = parseInt(arg, 10);\n  if (!KECCAK_SIZES.has(size)) throw new Error(`Unsupported Keccak size: ${arg}`);\n  return size;\n}","typeGuard":"function isValidKeccakSize(arg) {\n  return KECCAK_SIZES.has(parseInt(arg, 10));\n}","tryCatchPattern":"try {\n  return chef.Keccak(data, [size]);\n} catch (e) {\n  if (/Invalid size/.test(e.message)) throw new Error('Use 224, 256, 384, or 512');\n  throw e;\n}","preventionTips":["Select Size only from the dropdown.","When building recipes programmatically, validate against [224,256,384,512].","Add both an option value and a case branch for any new size."],"tags":["keccak","hash","crypto","argument-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}