{"record":{"id":"be2cb435cb49b05f","repo":"pxb1988/dex2jar","slug":"bad-base-64","errorCode":null,"errorMessage":"bad base-64","messagePattern":"bad base-64","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dex-tools/src/main/java/com/googlecode/d2j/signapk/Base64.java","lineNumber":159,"sourceCode":"     * <p>The padding '=' characters at the end are considered optional, but\n     * if any are present, there must be the correct number of them.\n     *\n     * @param input  the data to decode\n     * @param offset the position within the input array at which to start\n     * @param len    the number of bytes of input to decode\n     * @param flags  controls certain features of the decoded output.\n     *               Pass {@code DEFAULT} to decode standard Base64.\n     *\n     * @throws IllegalArgumentException if the input contains\n     * incorrect padding\n     */\n    public static byte[] decode(byte[] input, int offset, int len, int flags) {\n        // Allocate space for the most data the input could represent.\n        // (It could contain less if it contains whitespace, etc.)\n        Decoder decoder = new Decoder(flags, new byte[len*3/4]);\n\n        if (!decoder.process(input, offset, len, true)) {\n            throw new IllegalArgumentException(\"bad base-64\");\n        }\n\n        // Maybe we got lucky and allocated exactly enough output space.\n        if (decoder.op == decoder.output.length) {\n            return decoder.output;\n        }\n\n        // Need to shorten the array, so allocate a new one of the\n        // right size and copy.\n        byte[] temp = new byte[decoder.op];\n        System.arraycopy(decoder.output, 0, temp, 0, decoder.op);\n        return temp;\n    }\n\n    /* package */ static class Decoder extends Coder {\n        /**\n         * Lookup table for turning bytes into their position in the\n         * Base64 alphabet.","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-tools/src/main/java/com/googlecode/d2j/signapk/Base64.java#L141-L177","documentation":"This IllegalArgumentException is thrown by the Android-style Base64 decoder in d2j signapk when decoder.process() detects that the input bytes are not valid base-64 (illegal characters, bad padding, or truncated final quantum). The library uses this decoder when handling signed JARs, and it fails fast instead of returning partial data.","triggerScenarios":"Calling Base64.decode(byte[] input, int offset, int len, int flags) (or the delegating decode overloads) with bytes containing characters outside the base-64 alphabet, an '=' in a non-final position, or a length that is not a valid multiple of 4 (ignoring whitespace).","commonSituations":"Decoding a signature block or manifest digest that was corrupted, copied with surrounding text, line-wrapped with characters the decoder does not treat as whitespace, or is actually hex/plain text rather than base-64.","solutions":["Inspect and sanitize the input: strip non-base-64 characters (headers like '-----BEGIN...', newlines) before decoding.","Use the flag Base64.DEFAULT (or add Base64.URL_SAFE / NO_PADDING / NO_CLOSE as appropriate) to match how the data was originally encoded.","Verify the input length: raw base-64 without padding must be handled with NO_PADDING, or re-pad the input to a multiple of 4.","Confirm the byte source is correct — re-extract the data from the APK/JAR rather than decoding a truncated or hand-edited copy."],"exampleFix":"// before\nbyte[] data = Base64.decode(cert.getText().trim().getBytes(), 0);\n// after\nString b64 = cert.getText().replaceAll(\"-----[A-Z ]+-----|\\\\s\", \"\");\nbyte[] data = Base64.decode(b64.getBytes(), Base64.DEFAULT);","handlingStrategy":"validation","validationCode":"// validate before decoding\nString b64 = raw.replaceAll(\"-----[A-Z ]+-----|\\\\s\", \"\");\nif (!b64.matches(\"[A-Za-z0-9+/]*={0,2}\") || b64.length() % 4 != 0) {\n    throw new IllegalArgumentException(\"input is not valid base-64\");\n}\nbyte[] data = Base64.decode(b64.getBytes(), Base64.DEFAULT);","typeGuard":null,"tryCatchPattern":"try {\n    byte[] data = Base64.decode(input, Base64.DEFAULT);\n} catch (IllegalArgumentException e) {\n    // fall back to lenient decode or surface a clear 'corrupted signature' message\n}","preventionTips":["Strip PEM headers/footers and whitespace before decoding","Match decoder flags (URL_SAFE, NO_PADDING, NO_WRAP) to how the data was encoded","Never decode data copied from logs or documents; extract it programmatically"],"tags":["base64","decoding","illegal-argument"],"backgroundTag":"invalid-argument-format","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}