{"record":{"id":"a1ac017cbad31965","repo":"gchq/CyberChef","slug":"set-total-must-be-between-0000-and-9999","errorCode":null,"errorMessage":"Set Total must be between 0000 and 9999","messagePattern":"Set Total must be between 0000 and 9999","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/Colossus.mjs","lineNumber":424,"sourceCode":"\n        // Q1,Q2,Q3,Q4,Q5,negate,counter1\n        const qbusswitches = {\n            condition: [\n                {Qswitches: [args[9], args[10], args[11], args[12], args[13]], Negate: args[14], Counter: args[15]},\n                {Qswitches: [args[16], args[17], args[18], args[19], args[20]], Negate: args[21], Counter: args[22]},\n                {Qswitches: [args[23], args[24], args[25], args[26], args[27]], Negate: args[28], Counter: args[29]}\n            ],\n            condNegateAll: args[30],\n            addition: [\n                {Qswitches: [args[32], args[33], args[34], args[35], args[36]], Equals: args[37], C1: args[38]}\n            ],\n            addNegateAll: args[39],\n            totalMotor: args[40]\n        };\n\n        const settotal = parseInt(args[42], 10);\n        if (settotal < 0 || settotal > 9999)\n            throw new OperationError(\"Set Total must be between 0000 and 9999\");\n\n        // null|fast|slow for each of S1-5,M1-2,X1-5\n        const control = {\n            fast: args[43],\n            slow: args[44]\n        };\n\n        // Start positions\n        if (args[52]<1 || args[52]>43) throw new OperationError(\"Ψ1 start must be between 1 and 43\");\n        if (args[53]<1 || args[53]>47) throw new OperationError(\"Ψ2 start must be between 1 and 47\");\n        if (args[54]<1 || args[54]>51) throw new OperationError(\"Ψ3 start must be between 1 and 51\");\n        if (args[55]<1 || args[55]>53) throw new OperationError(\"Ψ4 start must be between 1 and 53\");\n        if (args[56]<1 || args[57]>59) throw new OperationError(\"Ψ5 start must be between 1 and 59\");\n        if (args[51]<1 || args[51]>37) throw new OperationError(\"Μ37 start must be between 1 and 37\");\n        if (args[50]<1 || args[50]>61) throw new OperationError(\"Μ61 start must be between 1 and 61\");\n        if (args[45]<1 || args[45]>41) throw new OperationError(\"Χ1 start must be between 1 and 41\");\n        if (args[46]<1 || args[46]>31) throw new OperationError(\"Χ2 start must be between 1 and 31\");\n        if (args[47]<1 || args[47]>29) throw new OperationError(\"Χ3 start must be between 1 and 29\");","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/Colossus.mjs#L406-L442","documentation":"Thrown when the parsed Set Total value (parseInt(args[42],10)) is outside 0–9999 inclusive. The Colossus counters are 4-decade decimal counters, so Set Total must be a four-digit-or-less non-negative number.","triggerScenarios":"Colossus.run reads args[42], parseInt's it base 10, and throws if <0 or >9999. A non-numeric string parses to NaN, and NaN comparisons are false so NaN slips through (no throw) — but a numeric value above 9999 or below 0 throws. Leading '−' or large values are the real triggers.","commonSituations":"User enters a 5-digit total, a negative number, or copies a hex-looking value expecting it parsed as decimal. NaN from empty/garbage input does NOT throw here (latent gap) but surfaces later.","solutions":["Enter a Set Total in the range 0000–9999 as a decimal integer.","Avoid negative values and values ≥10000.","Guard against NaN: if args[42] is non-numeric, supply 0 explicitly rather than relying on this check (NaN bypasses it)."],"exampleFix":"// before\n// args[42] = \"12345\"  // > 9999, throws\n// after\n// args[42] = \"9999\"","handlingStrategy":"validation","validationCode":"const settotal = parseInt(args[42], 10);\nif (!Number.isFinite(settotal) || settotal < 0 || settotal > 9999) { /* fix before run */ }","typeGuard":"function isValidSetTotal(v) { const n = parseInt(v, 10); return Number.isFinite(n) && n >= 0 && n <= 9999; }","tryCatchPattern":"null","preventionTips":["Enter Set Total as a decimal integer 0000–9999.","Guard NaN explicitly (empty/garbage input slips past the built-in check).","Avoid negatives and values ≥ 10000."],"tags":["colossus","numeric-range","input-validation","counter"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}