{"record":{"id":"9350652cc1762cf1","repo":"gchq/CyberChef","slug":"the-all-zero-group-char-cannot-appear-in-the-alpha","errorCode":null,"errorMessage":"The all-zero group char cannot appear in the alphabet","messagePattern":"The all-zero group char cannot appear in the alphabet","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/FromBase85.mjs","lineNumber":95,"sourceCode":"\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {byteArray}\n     */\n    run(input, args) {\n        const alphabet = Utils.expandAlphRange(args[0]).join(\"\"),\n            removeNonAlphChars = args[1],\n            allZeroGroupChar = typeof args[2] === \"string\" ? args[2].slice(0, 1) : \"\",\n            result = [];\n\n        if (alphabet.length !== 85 ||\n            [].unique.call(alphabet).length !== 85) {\n            throw new OperationError(\"Alphabet must be of length 85\");\n        }\n\n        if (allZeroGroupChar && alphabet.includes(allZeroGroupChar)) {\n            throw new OperationError(\"The all-zero group char cannot appear in the alphabet\");\n        }\n\n        // Remove delimiters if present\n        const matches = input.match(/^<~(.+?)~>$/);\n        if (matches !== null) input = matches[1];\n\n        // Remove non-alphabet characters\n        if (removeNonAlphChars) {\n            const re = new RegExp(\"[^~\" + allZeroGroupChar +alphabet.replace(/[[\\]\\\\\\-^$]/g, \"\\\\$&\") + \"]\", \"g\");\n            input = input.replace(re, \"\");\n            // Remove delimiters again if present (incase of non-alphabet characters in front/behind delimiters)\n            const matches = input.match(/^<~(.+?)~>$/);\n            if (matches !== null) input = matches[1];\n        }\n\n        if (input.length === 0) return [];\n\n        let i = 0;","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/FromBase85.mjs#L77-L113","documentation":"Thrown by From Base85 when the 'All-zero group char' (default 'z') is also a member of the alphabet. In Ascii85, the shorthand char represents a whole all-zero 4-byte group and must be distinct from every alphabet symbol; a collision would make decoding ambiguous. The check runs after the alphabet length/uniqueness validation.","triggerScenarios":"Using the default 'z' all-zero char with an alphabet that contains 'z' (e.g. a custom alphabet spanning lower-case letters); setting the all-zero char to a symbol that appears in the chosen alphabet; using the z85 alphabet which includes 'z' while keeping the default shorthand.","commonSituations":"Custom alphabet that inadvertently includes the shorthand char; switching alphabets without updating the all-zero group char; misunderstanding that 'z' shorthand is Ascii85-specific.","solutions":["Change the 'All-zero group char' to a character not present in the alphabet.","If the alphabet doesn't use 'z', keep the default; if it does, pick another char or empty it.","Set the all-zero group char to empty to disable the shorthand entirely."],"exampleFix":"// before: alphabet contains 'z' while shorthand is 'z'\nfromBase85.run(input, ['A-Za-z0-9!.', true, 'z']) // 'z' in alphabet\n// after: pick a non-colliding shorthand or disable it\nfromBase85.run(input, ['A-Za-z0-9!.', true, ''])","handlingStrategy":"validation","validationCode":"const alphabet = Utils.expandAlphRange(args[0]).join('');\nconst zeroChar = typeof args[2] === 'string' ? args[2].slice(0,1) : '';\nif (zeroChar && alphabet.includes(zeroChar)) {\n  // change zeroChar or clear it; do not call fromBase85.run()\n}","typeGuard":"function zeroCharIsDistinct(zeroChar, alphabet) {\n  return !zeroChar || !alphabet.includes(zeroChar);\n}","tryCatchPattern":"try {\n  fromBase85.run(input, args);\n} catch (e) {\n  if (e.type === 'OperationError' && /all-zero group char cannot appear/.test(e.message)) {\n    // pick a non-colliding all-zero char or set it empty\n  } else throw e;\n}","preventionTips":["Keep the all-zero group char distinct from every alphabet symbol.","Set the all-zero char to empty to disable the shorthand if unsure.","Re-check the shorthand char whenever you change the alphabet."],"tags":["base85","ascii85","alphabet","argument-validation","config"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}