{"record":{"id":"606b6c643a903be7","repo":"gchq/CyberChef","slug":"5-start-must-be-between-1-and-59","errorCode":null,"errorMessage":"Ψ5 start must be between 1 and 59","messagePattern":"Ψ5 start must be between 1 and 59","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/Colossus.mjs","lineNumber":437,"sourceCode":"            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\");\n        if (args[48]<1 || args[48]>26) throw new OperationError(\"Χ4 start must be between 1 and 26\");\n        if (args[49]<1 || args[49]>23) throw new OperationError(\"Χ5 start must be between 1 and 23\");\n\n        const starts = {\n            X1: args[45], X2: args[46], X3: args[47], X4: args[48], X5: args[49],\n            M61: args[50], M37: args[51],\n            S1: args[52], S2: args[53], S3: args[54], S4: args[55], S5: args[56]\n        };\n\n        const colossus = new ColossusComputer(input, pattern, qbusin, qbusswitches, control, starts, settotal, limit);\n        const result = colossus.run();\n\n        return result;","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/Colossus.mjs#L419-L455","documentation":"Intended to throw when the Ψ5 (S5) wheel start position args[56] is outside 1–59 (Ψ5 has 59 cam positions). WARNING: the guard reads args[56]<1 || args[57]>59 — the upper bound tests args[57] (an out-of-range index, past S5) instead of args[56]. This is a bug: a legitimately-too-large Ψ5 value (>59) will NOT trigger this error, and conversely the error can fire based on an unrelated argument.","triggerScenarios":"Colossus.run line 437: `if (args[56]<1 || args[57]>59)`. The lower-bound check on args[56] works, but the upper-bound uses args[57]. Real Ψ5 starts >59 pass silently; the throw instead depends on whatever occupies args[57].","commonSituations":"A user sets Ψ5 > 59 expecting an error and gets none (silent bad input), or gets a spurious Ψ5 error because args[57] (unrelated slot) exceeds 59. This is a code defect, not merely user misconfiguration.","solutions":["CODE FIX (upstream): change args[57] to args[56] in the upper-bound test so the guard matches its message.","Until fixed, validate Ψ5 (args[56]) yourself before calling the operation: ensure 1 ≤ value ≤ 59.","Do not rely on this built-in check to catch an over-range Ψ5 value.","Report the bug; the message is correct but the condition is wrong."],"exampleFix":"// before (buggy — line 437)\nif (args[56]<1 || args[57]>59) throw new OperationError(\"Ψ5 start must be between 1 and 59\");\n// after (corrected)\nif (args[56]<1 || args[56]>59) throw new OperationError(\"Ψ5 start must be between 1 and 59\");","handlingStrategy":"validation","validationCode":"// Built-in guard is BUGGY (tests args[57] for upper bound). Validate yourself:\nconst v = Number(args[56]);\nif (!Number.isFinite(v) || v < 1 || v > 59) { /* fix Ψ5 start before run */ }","typeGuard":"function inRange(v, lo, hi) { const n = Number(v); return Number.isFinite(n) && n >= lo && n <= hi; }","tryCatchPattern":"null","preventionTips":["Do NOT trust the built-in Ψ5 check — it reads the wrong arg index for the upper bound.","Always validate Ψ5 (args[56]) to 1–59 yourself before running.","Report/patch the upstream bug (args[57] → args[56] on line 437).","Use 1-based indexing."],"tags":["colossus","wheel-start","numeric-range","bug","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}