{"record":{"id":"d3841a412a0ba195","repo":"Tencent/tinker","slug":"unexpected-endian-tag-0x-endiantag","errorCode":null,"errorMessage":"Unexpected endian tag: 0x${endianTag}","messagePattern":"Unexpected endian tag: 0x(.+?)","errorType":"exception","errorClass":"DexException","httpStatus":null,"severity":"error","filePath":"third-party/aosp-dexutils/src/main/java/com/tencent/tinker/android/dex/TableOfContents.java","lineNumber":182,"sourceCode":"\n    private void readHeader(Dex.Section headerIn) throws UnsupportedEncodingException {\n        byte[] magic = headerIn.readByteArray(8);\n        api = DexFormat.magicToApi(magic);\n\n        if (api == -1) {\n            throw new DexException(\"Unexpected magic: \" + Arrays.toString(magic));\n        }\n\n        checksum = headerIn.readInt();\n        signature = headerIn.readByteArray(20);\n        fileSize = headerIn.readInt();\n        int headerSize = headerIn.readInt();\n        if (headerSize != SizeOf.HEADER_ITEM) {\n            throw new DexException(\"Unexpected header: 0x\" + Integer.toHexString(headerSize));\n        }\n        int endianTag = headerIn.readInt();\n        if (endianTag != DexFormat.ENDIAN_TAG) {\n            throw new DexException(\"Unexpected endian tag: 0x\" + Integer.toHexString(endianTag));\n        }\n        linkSize = headerIn.readInt();\n        linkOff = headerIn.readInt();\n        mapList.off = headerIn.readInt();\n        if (mapList.off == 0) {\n            throw new DexException(\"Cannot merge dex files that do not contain a map\");\n        }\n        stringIds.size = headerIn.readInt();\n        stringIds.off = headerIn.readInt();\n        typeIds.size = headerIn.readInt();\n        typeIds.off = headerIn.readInt();\n        protoIds.size = headerIn.readInt();\n        protoIds.off = headerIn.readInt();\n        fieldIds.size = headerIn.readInt();\n        fieldIds.off = headerIn.readInt();\n        methodIds.size = headerIn.readInt();\n        methodIds.off = headerIn.readInt();\n        classDefs.size = headerIn.readInt();","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/third-party/aosp-dexutils/src/main/java/com/tencent/tinker/android/dex/TableOfContents.java#L164-L200","documentation":"Thrown by TableOfContents.readHeader when the endian_tag (offset 40) is not DexFormat.ENDIAN_TAG (0x12345678). The dex format is little-endian-only in practice; the tag exists to catch byte-order confusion, and a wrong value usually means every int in the file is swapped relative to expectation.","triggerScenarios":"Reading a dex that was byte-swapped by a big-endian intermediary, a header written by a buggy custom generator, or (most commonly) a corrupt/garbage file that happened to pass the magic and header-size checks.","commonSituations":"Corruption cases dominate; occasionally custom build tooling that assembles headers field-by-field gets the tag wrong, or truncated files where reads land on unrelated bytes.","solutions":["Checksum-validate; if invalid, replace the file — do not attempt to byte-swap dexes back.","If you author dexes programmatically, write ENDIAN_TAG (0x12345678) little-endian at offset 40; compare against a d8-produced reference dex.","Add an early magic+tag sanity filter to batch inputs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"static boolean littleEndianTagOk(ByteBuffer b) { return b.getInt(40) == 0x12345678; }","typeGuard":null,"tryCatchPattern":"catch (DexException e) with 'Unexpected endian tag' -> classify corrupt; re-download/rebuild the artifact","preventionTips":["Verify SHA-1 signature field (offset 12..31) before deep parsing to get a precise corruption diagnosis."],"tags":["dex","endian","header","validation","tinker"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}