{"record":{"id":"7fc982ed28d078c3","repo":"Tencent/matrix","slug":"endian-constant-has-unexpected-value-integer-toh","errorCode":null,"errorMessage":"Endian constant has unexpected value ${Integer.toHexString(mHeaderItem.endianTag)}","messagePattern":"Endian constant has unexpected value (.+?)","errorType":"console","errorClass":"DexDataException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-commons/src/main/java/com/android/dexdeps/DexData.java","lineNumber":108,"sourceCode":"                    + \"this is a DEX file?\");\n            throw new DexDataException();\n        }\n\n        /*\n         * Read the endian tag, so we properly swap things as we read\n         * them from here on.\n         */\n        seek(8 + 4 + 20 + 4 + 4);\n        mHeaderItem.endianTag = readInt();\n        if (mHeaderItem.endianTag == HeaderItem.ENDIAN_CONSTANT) {\n            /* do nothing */\n        } else if (mHeaderItem.endianTag == HeaderItem.REVERSE_ENDIAN_CONSTANT) {\n            /* file is big-endian (!), reverse future reads */\n            isBigEndian = true;\n        } else {\n            System.err.println(\"Endian constant has unexpected value \"\n                    + Integer.toHexString(mHeaderItem.endianTag));\n            throw new DexDataException();\n        }\n\n        seek(8 + 4 + 20);  // magic, checksum, signature\n        mHeaderItem.fileSize = readInt();\n        mHeaderItem.headerSize = readInt();\n        /*mHeaderItem.endianTag =*/ readInt();\n        /*mHeaderItem.linkSize =*/ readInt();\n        /*mHeaderItem.linkOff =*/ readInt();\n        /*mHeaderItem.mapOff =*/ readInt();\n        mHeaderItem.stringIdsSize = readInt();\n        mHeaderItem.stringIdsOff = readInt();\n        mHeaderItem.typeIdsSize = readInt();\n        mHeaderItem.typeIdsOff = readInt();\n        mHeaderItem.protoIdsSize = readInt();\n        mHeaderItem.protoIdsOff = readInt();\n        mHeaderItem.fieldIdsSize = readInt();\n        mHeaderItem.fieldIdsOff = readInt();\n        mHeaderItem.methodIdsSize = readInt();","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-commons/src/main/java/com/android/dexdeps/DexData.java#L90-L126","documentation":"After magic validation, DexData.parseHeaderItem reads the endian tag, which must equal ENDIAN_CONSTANT (0x12345678, little-endian) or REVERSE_ENDIAN_CONSTANT (0x78563412, big-endian). Any other value means the header is corrupt or the file isn't really a dex despite passing the magic check; it throws DexDataException.","triggerScenarios":"parseHeaderItem (via load) reads an endianTag other than the two defined constants — bit-rotated/truncated dex, a file that coincidentally starts with dex magic but has damaged header, or wrong-offset reads caused by prior parsing bugs.","commonSituations":"Corrupted dexes from interrupted builds or bad file transfer; dexes modified by post-processing tools (repackaging, optimization) that broke the header; exotic big-endian-produced artifacts mis-handled by tooling.","solutions":["Rebuild or re-obtain the dex; a bad endian tag almost always means corruption.","Check endianness handling in whatever wrote/modified the dex — byte-swapped headers indicate a broken repacking tool.","Verify with `dexdump` or `d8` that the file opens in standard tooling; if not, the file is bad, not this library.","Compare file size and checksum/signature fields against the APK's copy to detect truncation."],"exampleFix":"// before\nDexData dexData = new DexData(raf);\ndexData.load(); // throws on bad endian tag\n// after\ntry {\n    dexData.load();\n} catch (DexDataException e) {\n    MatrixLog.w(TAG, \"corrupt dex header, skipping: \" + inputPath);\n}","handlingStrategy":"try-catch","validationCode":"// verify dex integrity via header before load\nbyte[] header = readBytes(f, 0, 112);\nint endianTag = ByteBuffer.wrap(header, 40, 4).order(ByteOrder.LITTLE_ENDIAN).getInt();\nboolean ok = endianTag == 0x78563412L || endianTag == 0x12345678L;","typeGuard":null,"tryCatchPattern":"try {\n    dexData.load();\n} catch (DexDataException e) {\n    Log.w(TAG, \"corrupt dex header (bad endian tag), skipping \" + inputPath);\n}","preventionTips":["Check the dex file size matches the header's fileSize field to detect truncation.","Avoid post-processing tools that rewrite dex headers without fixing endian/checksum fields.","Validate with standard tooling (dexdump) when a dex repeatedly fails.","Re-transfer/rebuild files that fail — bad endian tag means corruption, not a config issue."],"tags":["dex","file-format","endianness","static-analysis"],"backgroundTag":"checksum-mismatch","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}