{"record":{"id":"0d139d9bfe415612","repo":"MyCATApache/Mycat-Server","slug":"illegal-character-c","errorCode":null,"errorMessage":"Illegal character {c}","messagePattern":"Illegal character (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/util/DecryptUtil.java","lineNumber":387,"sourceCode":"\t                int ch2 = base64toInt(s.charAt(inCursor++), alphaToInt);\n\t                result[outCursor++] = (byte) ((ch1 << 4) | (ch2 >> 2));\n\t            }\n\t        }\n\t        // assert inCursor == s.length()-missingBytesInLastGroup;\n\t        // assert outCursor == result.length;\n\t        return result;\n\t    }\n\n\t    /**\n\t     * Translates the specified character, which is assumed to be in the \"Base 64 Alphabet\" into its equivalent 6-bit\n\t     * positive integer.\n\t     * \n\t     * @throw IllegalArgumentException or ArrayOutOfBoundsException if c is not in the Base64 Alphabet.\n\t     */\n\t    private static int base64toInt(char c, byte[] alphaToInt) {\n\t        int result = alphaToInt[c];\n\t        if (result < 0) {\n\t            throw new IllegalArgumentException(\"Illegal character \" + c);\n\t        }\n\t        return result;\n\t    }\n\n\t    /**\n\t     * This array is a lookup table that translates unicode characters drawn from the \"Base64 Alphabet\" (as specified in\n\t     * Table 1 of RFC 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64\n\t     * alphabet but fall within the bounds of the array are translated to -1.\n\t     */\n\t    private static final byte base64ToInt[]    = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n\t            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62,\n\t            -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7,\n\t            8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28,\n\t            29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };\n\n\t    /**\n\t     * This array is the analogue of base64ToInt, but for the nonstandard variant that avoids the use of uppercase\n\t     * alphabetic characters.","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/util/DecryptUtil.java#L369-L405","documentation":"base64toInt performs a table lookup (alphaToInt[c]) mapping each Base64 character to its 6-bit value; unmapped characters map to negative sentinels. If a character is not in the expected Base64 alphabet, it throws IllegalArgumentException('Illegal character <c>').","triggerScenarios":"Decoding a string containing characters outside the standard (or alternate) Base64 alphabet — whitespace, newlines, '\\r', '\\n', '-', '_', '!', or non-ASCII characters — passed into the decoder reached via decrypt flows.","commonSituations":"MIME-wrapped Base64 with embedded line breaks; URL-safe Base64 ('-','_') fed to the standard-alphabet decoder; trailing newline from file reads; corrupted ciphertext.","solutions":["Strip all whitespace/newlines from the string before decoding: s.replaceAll(\"\\\\s\",\"\")","If the data is URL-safe Base64, replace '-' with '+' and '_' with '/' first","Verify the alphabet: this decoder supports a standard and an alternate table; ensure the encoding matches the one selected","Re-encode the original bytes with a standard Base64 encoder if the input source is untrusted"],"exampleFix":"// before\ndecode(rawBase64FromFile); // contains trailing \\n\n// after\ndecode(rawBase64FromFile.replaceAll(\"\\\\s\", \"\"));","handlingStrategy":"validation","validationCode":"static String sanitizeBase64(String s){\n    if (s == null) return null;\n    return s.replaceAll(\"\\\\s\",\"\").replace('-','+').replace('_','/');\n}","typeGuard":null,"tryCatchPattern":"try { return decode(sanitized); }\ncatch (IllegalArgumentException e) { throw new IllegalArgumentException(\"non-Base64 character in input at decode\", e); }","preventionTips":["Strip all whitespace/newlines (MIME wrapping) before decoding","Convert URL-safe Base64 alphabet characters to the standard alphabet","Ensure the string is read with the right charset so no non-ASCII chars slip in","Validate with a regex over the standard alphabet before calling the decoder"],"tags":["java","base64","decoding"],"backgroundTag":"invalid-argument-format","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}