{"record":{"id":"2a7e05d8486bd499","repo":"gchq/CyberChef","slug":"invalid-size-2a7e05","errorCode":null,"errorMessage":"Invalid size","messagePattern":"Invalid size","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/SHA3.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.sha3_224;\n                break;\n            case 384:\n                algo = JSSHA3.sha3_384;\n                break;\n            case 256:\n                algo = JSSHA3.sha3_256;\n                break;\n            case 512:\n                algo = JSSHA3.sha3_512;\n                break;\n            default:\n                throw new OperationError(\"Invalid size\");\n        }\n\n        return algo(input);\n    }\n\n}\n\nexport default SHA3;\n","sourceCodeStart":42,"sourceCodeEnd":69,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/SHA3.mjs#L42-L69","documentation":"Thrown by the SHA3 operation when the parsed size is not one of 224, 256, 384, or 512. The Size argument is a fixed option dropdown (['512','384','256','224']), so through the UI this is unreachable; it only fires when the operation is invoked programmatically with an invalid size.","triggerScenarios":"Calling SHA3.run(input, ['1024']) or any args[0] that parseInt to a value outside the supported set. A non-numeric string like 'abc' parseInts to NaN and also hits the default.","commonSituations":"Node API usage with a hand-built args array; a recipe export from a modified/forked CyberChef that added a size value; integration code that reads size from user input without validation.","solutions":["Set Size to one of: 224, 256, 384, or 512.","If sourcing the size dynamically, validate parseInt(args[0]) is in [224,256,384,512] before calling."],"exampleFix":"// before\nsha3.run(buf, [\"1024\"])\n// after\nsha3.run(buf, [\"512\"])","handlingStrategy":"validation","validationCode":"const VALID_SHA3 = [224, 256, 384, 512];\nconst size = parseInt(sizeArg, 10);\nif (!VALID_SHA3.includes(size)) {\n  throw new Error(`SHA3 size must be one of ${VALID_SHA3.join(\", \")}`);\n}","typeGuard":"function isSha3Size(v) {\n  return [224, 256, 384, 512].includes(parseInt(v, 10));\n}","tryCatchPattern":null,"preventionTips":["Restrict size selection to the four supported values.","When building args programmatically, source size from the constructor default list."],"tags":["crypto","hash","sha3","operation","argument"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}