{"record":{"id":"354066dfcdc8c670","repo":"pxb1988/dex2jar","slug":"bad-second-or-third-byte","errorCode":null,"errorMessage":"bad second or third byte","messagePattern":"bad second or third byte","errorType":"exception","errorClass":"UTFDataFormatException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/util/Mutf8.java","lineNumber":55,"sourceCode":"        while (true) {\n            char a = (char) (in.get() & 0xff);\n            if (a == 0) {\n                return sb.toString();\n            }\n\n            if (a < '\\u0080') {\n                sb.append(a);\n            } else if ((a & 0xe0) == 0xc0) {\n                int b = in.get() & 0xff;\n                if ((b & 0xC0) != 0x80) {\n                    throw new UTFDataFormatException(\"bad second byte\");\n                }\n                sb.append((char) (((a & 0x1F) << 6) | (b & 0x3F)));\n            } else if ((a & 0xf0) == 0xe0) {\n                int b = in.get() & 0xff;\n                int c = in.get() & 0xff;\n                if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) {\n                    throw new UTFDataFormatException(\"bad second or third byte\");\n                }\n                sb.append((char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F)));\n            } else {\n                throw new UTFDataFormatException(\"bad byte\");\n            }\n        }\n    }\n\n    /**\n     * Returns the number of bytes the modified UTF8 representation of 's' would take.\n     */\n    private static long countBytes(String s, boolean shortLength) throws UTFDataFormatException {\n        long result = 0;\n        final int length = s.length();\n        for (int i = 0; i < length; ++i) {\n            char ch = s.charAt(i);\n            if (ch != 0 && ch <= 127) { // U+0000 uses two bytes.\n                ++result;","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/util/Mutf8.java#L37-L73","documentation":"Thrown by Mutf8.decode when a lead byte indicated a 3-byte sequence (0xE0-0xEF) but either the second or third continuation byte is missing its 10xx xxxx pattern. The byte stream is not valid Modified UTF-8.","triggerScenarios":"Decoding a DEX string where the 3-byte sequence bytes are corrupted, or the buffer position is misaligned so continuation bytes land on unrelated data.","commonSituations":"Corrupted DEX files, incorrect offset computation into string_data, mixed non-MUTF-8 encoders writing strings into DEX-like blobs.","solutions":["Verify the decode start offset is the byte after the ULEB128 length in string_data","Re-obtain the DEX file; corruption is likely","Catch UTFDataFormatException and skip/report the bad string index instead of failing the whole file"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"if ((b & 0xC0) != 0x80 || (c & 0xC0) != 0x80) return false; // pre-check continuation bytes for 3-byte sequences","typeGuard":"boolean isContinuation(int b) { return (b & 0xC0) == 0x80; }","tryCatchPattern":"try { return Mutf8.decode(buf, pos); } catch (UTFDataFormatException e) { throw new DexException(\"invalid string data at offset \" + pos[0], e); }","preventionTips":["Verify buffer alignment before decoding 3-byte sequences","Check DEX file integrity (checksum) before parsing","Fail fast on the first bad string rather than proceeding with a drifted position"],"tags":["utf-8","dex","decoding","corrupt-input"],"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"}