gchq/CyberChef · error · OperationError
Invalid size
Error message
Invalid size
What it means
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).
Source
Thrown at src/core/operations/Keccak.mjs:60
run(input, args) {
const size = parseInt(args[0], 10);
let algo;
switch (size) {
case 224:
algo = JSSHA3.keccak224;
break;
case 384:
algo = JSSHA3.keccak384;
break;
case 256:
algo = JSSHA3.keccak256;
break;
case 512:
algo = JSSHA3.keccak512;
break;
default:
throw new OperationError("Invalid size");
}
return algo(input);
}
}
export default Keccak;
View on GitHub (pinned to 4290ea7539)
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.
Example fix
// before: hand-edited recipe size chef.Keccak(data, ['1024']); // parseInt -> NaN -> default // after: supported size chef.Keccak(data, ['512']);
Defensive patterns
Strategy: validation
Validate before calling
const KECCAK_SIZES = new Set([224, 256, 384, 512]);
function ensureKeccakSize(arg) {
const size = parseInt(arg, 10);
if (!KECCAK_SIZES.has(size)) throw new Error(`Unsupported Keccak size: ${arg}`);
return size;
} Type guard
function isValidKeccakSize(arg) {
return KECCAK_SIZES.has(parseInt(arg, 10));
} Try / catch
try {
return chef.Keccak(data, [size]);
} catch (e) {
if (/Invalid size/.test(e.message)) throw new Error('Use 224, 256, 384, or 512');
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Size must be greater than 0
- Invalid size
- Invalid block cipher mode: ${mode}
- Invalid ciphertext length: ${originalLength} bytes. Must be
- No padding requested but input is not a ${blockSize}-byte mu
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/9612ad787a7c744e.
Report an issue: GitHub.