{"record":{"id":"5e27884334ed1346","repo":"pxb1988/dex2jar","slug":"fail-to-load-string-d-08x","errorCode":null,"errorMessage":"fail to load string %d@%08x","messagePattern":"fail to load string (.+?)@%08x","errorType":"exception","errorClass":"DexException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java","lineNumber":973,"sourceCode":"        methoIdIn.position(id * 8);\r\n        int owner_idx = 0xFFFF & methoIdIn.getShort();\r\n        int proto_idx = 0xFFFF & methoIdIn.getShort();\r\n        int name_idx = methoIdIn.getInt();\r\n        return new Method(getType(owner_idx), getString(name_idx), getProto(proto_idx));\r\n    }\r\n\r\n    private String getString(int id) {\r\n        if (id == -1) {\r\n            return null;\r\n        }\r\n        int offset = stringIdIn.getInt(id * 4);\r\n        stringDataIn.position(offset);\r\n        int length = readULeb128i(stringDataIn);\r\n        try {\r\n            StringBuilder buff = new StringBuilder((int) (length * 1.5));\r\n            return Mutf8.decode(stringDataIn, buff);\r\n        } catch (UTFDataFormatException e) {\r\n            throw new DexException(e, \"fail to load string %d@%08x\", id, offset);\r\n        }\r\n    }\r\n\r\n    private String getType(int id) {\r\n        if (id == -1) {\r\n            return null;\r\n        }\r\n        return getString(typeIdIn.getInt(id * 4));\r\n    }\r\n\r\n    private int acceptField(ByteBuffer in, int lastIndex, DexClassVisitor dcv,\r\n            Map<Integer, Integer> fieldAnnotationPositions, Object value, int config) {\r\n        int diff = readULeb128i(in);\r\n        int field_access_flags = readULeb128i(in);\r\n        int field_id = lastIndex + diff;\r\n        Field field = getField(field_id);\r\n        // //////////////////////////////////////////////////////////////\r\n        DexFieldVisitor dfv = dcv.visitField(field_access_flags, field, value);\r","sourceCodeStart":955,"sourceCodeEnd":991,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java#L955-L991","documentation":"When resolving a string id, Mutf8.decode hit a UTFDataFormatException while decoding the MUTF-8 bytes of the string_data_item at the given offset. The reader wraps it in a DexException with the string id and hex offset so you can locate the bad entry. The dex's string table contains bytes that are not valid MUTF-8 or run past the end of the data section.","triggerScenarios":"A string_ids/string_data entry whose modified-UTF-8 is invalid (e.g. raw surrogates encoded wrongly, truncated continuation bytes) or whose offset points outside valid data — corrupted dex, bad string_ids offsets, or non-dex bytes in the string section.","commonSituations":"Corrupted downloads/extractions of APKs; dex edited by string-rewriting tools that broke MUTF-8 encoding; malicious/packed apps with invalid string tables processed by dex2jar.","solutions":["Re-obtain or re-extract the dex file — verify checksum/signature (the dex header stores both)","Use the id@offset in the message to hexdump the failing string_data_item and check the bytes","If you control the source, rebuild with d8/dx to regenerate a valid string table","For robustness, patch Mutf8.decode usage to substitute invalid sequences instead of throwing if you must tolerate dirty inputs"],"exampleFix":"// before\n// java -jar dex2jar.jar broken.apk -> DexException: fail to load string 42@0001a2b0\n// after\n// adb shell or unzip -t app.apk  # verify archive integrity, re-extract classes.dex\n// then check header: head -c 12 classes.dex | xxd (magic + checksum)","handlingStrategy":"validation","validationCode":"static boolean dexChecksumOk(byte[] dex) throws java.security.NoSuchAlgorithmException {\n    if (dex.length < 12) return false;\n    java.util.zip.Adler32 a = new java.util.zip.Adler32();\n    a.update(dex, 12, dex.length - 12);\n    int stored = (dex[8]&0xFF) | (dex[9]&0xFF)<<8 | (dex[10]&0xFF)<<16 | (dex[11]&0xFF)<<24;\n    return (int) a.getValue() == stored;\n}\n// reject files failing the Adler-32 checksum before DexFileReader touches the string table","typeGuard":null,"tryCatchPattern":"try {\n    new DexFileReader(file).accept(visitor);\n} catch (DexException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"fail to load string\")) {\n        throw new java.io.IOException(\"Corrupt DEX string table in \" + file\n            + \" (\" + e.getMessage() + \"); re-extract or rebuild the dex\", e);\n    }\n    throw e;\n}","preventionTips":["Verify the dex Adler-32 checksum and SHA-1 signature from the header before parsing","Re-extract APK entries rather than reusing possibly truncated dex copies","Treat this as data corruption: id@offset in the message pinpoints the bad string for forensics"],"tags":["dex","utf8","string-table"],"backgroundTag":"invalid-identifier-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"}